|
No, I cannot "just write ..." QTconcurent will not accept more than 5 parameters, hence std:bind is used to bypass that.
I believe I need somebody who can interpret the errors.../.
|
|
|
|
|
Member 14968771 wrote: QTconcurent will not accept more than 5 parameters,
What's your source for this statement. The docs Concurrent Run | Qt Concurrent 5.15.8 do not mention any limit. Assuming that its a C++ template using a parameter pack, the only limit I would expect would be your pthread stack size, which defaults to 8M, so for all intents an purposes not an issue.
One thing I would note is that hci_inquiry returns an int so I think the template parameter to QFuture should probablby be:
QFuture<int> future = QTconcurrent::run( ... )
Keep Calm and Carry On
|
|
|
|
|
I got this second hand and did not bother to verify the parameters # limit.
I am busy rebuilding my text code and will be able to try the function without std::bind.
Well - until I can get pass the errors I really do not care if the return values is wrong.
That puts me back to the original post - how do I know which is causing the error - wrong parameters , wrong # of parameters , incorrect return ... all of these are C++_ issues , very little to do with QT.
( ...but for some who cannot read it looks as QT problem...)
Cheers
|
|
|
|
|
Here us my latest test code
it does prove that
Qt Concurrent takes max of five "arguments" and lets leave it be...
Secondly
I found the "ducks" error.
And not sure how to react to it.
QT passes "arguments" to the run function ,
then QT expect / does this ( as a example )
int integer = 5;
if the argument is of "TYPE" integer.
( I have not tried to assign any arbitrary symbol )
then QT expect the symbol "integer" to passed as (??) to the "run" function...
..and it it fails , it identifies the failure source as "TYPE"
not as parameter or argument - just "TYPE"...
Maybe that is normal , but what a pain to debug.
extern int bFunction(
int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7,
int arg8
);
int integer = 5;
QFuture<int> future = QtConcurrent::run(
std::bind(
bFunction,
integer,
integer,
integer,
integer,
integer,
integer,
integer,
integer
)
);
|
|
|
|
|
Did some testing of my own over the weekend and I can confirm that QtConcurrent::run() does not like more than 5 parameters. Maybe the thing to do is to look into std::async, std::future as it does not seem to be limited and provides the same functionality. There's a couple of videos on them here: C++ Weekly - Ep 9 std::future Quick-Start - YouTube and here: C++ Weekly - Ep 11 std::future Part 2 - YouTube. Unless there's something in QtConcurrent that ties in better with your QT project, std::async and std::future may server you better.
As a point of interest, why QT? If you're on Ubuntu, and not using Kubuntu, I would have thought that maybe GTK+ would provide a more consistent look-&-feel. There are C++ bindings available (gtkmm), so if you're on a QT/C++ learning curve it would be about the same for you. There's no integrated IDE with gtk, but there's plenty of IDE's out there that will play nicely. Or you could go "hardcore" and learn how to write Makefiles!
Keep Calm and Carry On
|
|
|
|
|
I appreciate confirmation of the parameters # limit .
I do not see why QT limitation of one process would be a reason to switch OS, especially when
using std::bind "fixes " this limitation.
I have SUCCESSFULLY codded and run several test function using QTConcurrent,
and I am basically back where I started.
I could use some more assistance with this.
The attached code is direct from QT documentation.
What I do not understand is the necessity of highlighted code.
What is the purpose and is there a doc I could RTFM to get some
understanding why this code is necessary.
If I pass the aFunctionWithArguments function arguments at face value I then get
the "type" error ( as posted previously )
Is this something "just QT " or is that "normal" C++
and if so what is the correct terminology of doing this ?
I just call it "SYMBOLS".
My real code gets complicated because I am a passing more the 5 "arguments" and two of them are
pointer and double pointer.
I can run my test function passing struct and have no need for these "SYMBOLS".
I am NOT asking to write my code, I am asking for explanation why
QT is using these "conversions / symbols "
extern void aFunctionWithArguments(int arg1, double arg2, const QString &string);
int integer = ...;
double floatingPoint = ...;
QString string = ...;
QFuture<void> future = QtConcurrent::run(aFunctionWithArguments, integer, floatingPoint, string);
|
|
|
|
|
Member 14968771 wrote: ( ...but for some who cannot read it looks as QT problem...) Adding comments like that is unnecessary, and does not encourage people to help further.
|
|
|
|
|
Member 14968771 wrote: QTconcurent will not accept more than 5 parameters Reminds me of when I worked for a company about to publish a completely rewritten FORTRAN compiler: The release was pushed by one (significant) customer who had run into the old compiler's limit on 99 (ninety-nine) parameters to one function. The new compiler would allow 128 parameters, but it could easily be extended to 256 in future compiler versions.
I sort of accept that when going above a certain limit (isn't it 4 for the ARM ABI?), there is an increased cost. Five is probably acceptable. The day it grows beyond 99, I think you are on the wrong track 
|
|
|
|
|
It reminds me of an adage or axiom or some such that my prof stated in class back in university days that went something like "If you function has more than 5 parameters, you've forgotten one!"
Keep Calm and Carry On
|
|
|
|
|
I merely said, "the documentation suggests ...". I do not have Qt on my system so I am not able to test it.
|
|
|
|
|
As a debugging note
if just the number of parameters passed, irregardless if the are "plain arguments" or these funky symbols
do not match -
the error is "run" " cannot find the function " .
The "TYPE" error is definitely my wrong way of "symbolizing" the pointers.
Unfortunately the error does not clearly identify which "symbol" is not correct.
I'll try to find a real hci function which does not use pointers to verify this assumption.
|
|
|
|
|
Here is "semifinal " version of WORKING code
int status = 10;
qDebug() << "Status " << QString::number(status);
time->start();
status = hci_inquiry(
dev_id,
len,
max_rsp,
NULL,
&ii,
flags);
time->start();
QFuture<int> future = QtConcurrent::run(
std::bind(
hci_inquiry,
dev_id,
len,
max_rsp,
lap,
&ii,
flags)
);
future.waitForFinished();
qDebug() <<"hci_inquiry elapsed time " <<QString::number(time->elapsed());
qDebug() <<"hci_inquiry result " <<QString::number(future.result());
I STILL do not understand why "plain function : usage " works with "lap" as NULL and QtConcurent usage DOES NOT. As I said before - I am not so sure I have only one version of hci_inquiry....
The be truthful - I need to get back to source code and try to build my own description for the hci_inquiry code.
It has been educational so far....
PS by semifinal - I need to "move" the QT version to its own object / library.
|
|
|
|
|
Try using nullptr instead of NULL. NULL is defined as a macro, often the equivalent of #define NULL ((void *)0) . That was fine for C, but C++ has stricter rules about converting to/from NULL pointers, so you should use nullptr, particularly when you want to pass a null pointer to a function.
Keep Calm and Carry On
|
|
|
|
|
Hope no one screams at me but if they do I guess its okay this question is simple its ridiculous
but here goes my total number in decimal is 1,621,270,208 the number I am trying to figure out the percent is from is 1,604,667,016
I did this calculation on the web and it came out to 98% the two number the first being total is a int the second unalloc is also a int. the variable percent is a double or float
I thought mistaking that percent = unalloc / total woudgive me 0000.98 in percent but I realize that since the quotient is zero percent is 000.000 doing percent = unalloc % total would give the reminder in percent and thus a value of 1604665335.000 I have searched the web I know this is real simple to some of you wonder if you could help
thanks in advance
|
|
|
|
|
Presumably you're doing something like
int total = 100;
int unalloc = 96;
double percent = unalloc/total;
So the problem here is that since unaloc and total are both int , the calculation is done in integer math, and then promoted to double. What you need to do is to promote either operand to the division to double (or both):
double percent = (double)unalloc/total:
Keep Calm and Carry On
|
|
|
|
|
that was it thank you so so so much
|
|
|
|
|
hey k5054 my comment does not relate to the currently running thread. I just wanted to let you know I keep getting back to some of your replies in topic I have posted quite a while ago. I thought it might be a good idea to let you know I`m haunting those posts.
|
|
|
|
|
Hey lookee here ... a joke icon!
That's what I needed the other day. Oh well. 
|
|
|
|
|
double total = 1621270208;
double percentFrom = 1604667016;
double percent = percentFrom / total * 100;
|
|
|
|
|
|
I understand the concept of using ellipsis to pass variable number of parameters to a function.
However, the tutorial examples pass a simple values to demonstrate the workings of "list" .
I like to pass a object / widget (pointer) parameter and process the passed
parameter.
For example equivalent to this:
object -> add text (text )
Can that be done and if so can you post actual C++ code ?
Am I actually trying to do similar as passing a function as a parameter ?
My code call looks like this
ellipsisFunction( 2, listWidget_1, lisTWidget_2)
/* va_start example */
#include <stdio.h> /* printf */
#include <stdarg.h> /* va_list, va_start, va_arg, va_end */
void PrintFloats (int n, ...)
{
int i;
double val;
printf ("Printing floats:");
va_list vl;
va_start(vl,n);
for (i=0;i
|
|
|
|
|
If you pass a list of random types (numbers, strings, objects), then your function needs some method of determining what each reference is. That is why printf (and its derivatives) requires a format string to identify the type of each parameter.
|
|
|
|
|
I am aware that compiler by itself cannot determine the type of variable passed.
What I am missing is - how iterating thru the list works .
|
|
|
|
|
I'm not sure exactly where you're stuck. But lets start with the example you gave in your original post:
void PrintFloats (int n, ...)
{
int i;
double val;
printf ("Printing floats:");
va_list vl;
va_start(vl,n);
for (i=0;i
Assuming that you're stuck here, then you might complete this something like
for(i = 0; i < n; ++i) {
val = va_arg(vl, float);
printf("%f ", val);
}
va_end(vl);
putchar('\n');
In this case I'm assuming that the int n parameter tells the function how many float values to expect. Other options to tell a variadic function how many arguments to expect are to use some sort of format string, like printf() does, or you can use some sort of sentinel value for your function e.g.
PrintFloats(1.1, 2.2, -15.2, nan("")); In this case we have assumed that a NaN won't be part of the input string, so is a fair choice for a sentinel.
Keep Calm and Carry On
|
|
|
|
|
OK, let's move on.
The variadic function contains the passed parameters count.
The va_arg gets the parameter TYPE and according to the doc it has to match some specification.
( I gather the type can be also passed...but that is way over my head for now )
If I desire to pass type which does not meet this spec - all bets are off.
I am trying to pass a pointer to an object.
Does that sounds reasonable ?
The example I used has type float
for(i = 0; i < n; ++i) {
val = va_arg(vl, float); replacing float with an object
printf("%f ", val);
}
va_end(vl);
putchar('\n');
|
|
|
|
|