Hello,
i have a int variable and want to pass it to Q_ARG but i need that Q_ARG knows automatically what datatype the second argument is. Is there any way to do that?
thx
Hello,
i have a int variable and want to pass it to Q_ARG but i need that Q_ARG knows automatically what datatype the second argument is. Is there any way to do that?
thx
That doesn't make any sense.
Maybe describe what you want to do?
Cheers,
_
why does it not make sense?
Q_ARG(datatype,5)
5 is my int and i want that Q_ARG automatically knows what datatype is
auto does not work
i have a qstring like this ("5 5.4 test") and i need to reinterpret the parts of the qstring to datatype and value. thats no problem. but problem is that i cannot use is when i know the datatype in a kind of loop. cause qstrings cannot be converted into datatypes as far as i know.
Last edited by Ini; 7th January 2016 at 19:42.
The Q_ARG() pre-processor macro stringifies its first argument so the compiler never sees the auto keyword. (See qobjectdefs.h)
If, at compile time, you do not know the type of the value you are going to pass to the slot with invokeMethod() then that slot also cannot know the type. The slot must therefore be written to accept any type and the easiest way to do that is to accept a QVariant type. Within the slot you can try to differentiate the input on the basis of its QVariant::type() and QVariant::canConvert().
In any case, you have the problem that "5" might be meant as an int, short int, long long, char, float, double, long double, or as a string.
Bookmarks