|
I'm net entirely clear on what you're trying to do.
Normally, a library that is expected to be used by a developer is supplied with a header file that describes the contents of the library, that is #includ ed in the source file of user created software. That's what stdio.h or iostream do for you. If at all possible, you should look for the developer tools for your library and use the supplied headier.
Alternatively - and this is only as a last resort for the well-informed and foolhardy, there's no reason you can't declare the function in your own source code. But, you really have to know what the function signature is. If you have a mismatch, then you're almost certainly going to invoke Undefined Behavior, and then all bets about the validity of anything your program produces is suspect.
So for example, we know that the signature for a cosine function in the c standard library is double cos(double x; . Now normally we would write
#include <math.h>
double val = cos(2.5);
But it's perfectly valid to write
double cos(double x);
double val = cos(2.5);
But as I state above, you need to be sure that you've got the right signature for your function. If for example we were to write
double cos(int x); double val = cos(2.5)
/ ... Then the compiler will convert the 2.5 to an integer (e.g. a 4 byte value containing the value 0x02), and then pass that to the math library cos() function. On the library side, the code is expecting a double (e.g an 8 byte value in IEEE floating point format), so it will dutifully use the top 8 bytes of the stack for the value to calculate the cosine for. As you can see, we've only put 4 bytes on the stack in our call, and so half the data its using to calculate is, in essence, random data. Clearly, in this case we can't rely on what value cos() returns to us.
This is not the same as passing an int to cos() that has been properly declared. In that case, the compiler knows that the cos() function is expecting a double as its argument, so it provides a conversion from int to double at compile time.
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
First, the function you are trying to call is hci_inquiry not hci-inquiry . The second is an invalid identifier, and the compiler should be trying to parse this as hci - inqury . Not the same thing at all.
Second, looking at the documentation (RTFM! RTFM!), it looks like you probably want to use Qt::Concurrent::run() . Maybe start another thread and include the code that (a) works and (b) fails - plus what the failure mode is. As it is I'm blindly guessing at what you're doing and what may or may not be going wrong for you.
Third, Maybe look for a QT support forum. This forum isn't really intended to help with QT, but with C, C++ or MFC. I think I'm safe in saying that QT lies outside those bounds. It might be that there's noone here particularly well versed in QT.
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Looking at the documentation at Concurrent Run | Qt Concurrent 5.15.8[^], it suggests you should be able to write:
QFuture<void> future_hci = QtConcurrent::run(
hci_inquiry,
dev_id,
len,
max_rsp,
NULL,
&ii,
flags);
But as k5054 already said, this is the C/C++ forum. For Qt issues you need to find a specialist forum. My feeling would be to write a small test program using the Qt run function with different parameters to check that it does work for the different situations. Once you overcome that issue then you should be able to focus more on the HCI stuff.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
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
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
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;
|
|
|
|