PDA

View Full Version : passing QMultiMap to Q_ARG?



hunsrus
24th August 2012, 15:05
Hi everybody,

I'm trying to pass the following Map to Qts Meta-System to the method QMetaObject::invokeMethod:


QMultiMap<QString, int>

using


QMetaObject::invokeMethod(object,
"method",
Qt::BlockingQueuedConnection,
Q_ARG(QMultiMap<QString, int>, m_map));


where m_map is defined as:

QMultiMap<QString, int> m_map;

Using the statement above I get:
macro "Q_ARG" passed 3 arguments, but takes just 2

Surrounding the QMultiMap as follows:

Q_ARG((QMultiMap<QString, int>), m_map));

results in:
template argument 1 is invalid

Does anyone know how to pass Generic containers as QMap or QMultiMap to invokeMethod?

Thanks in advance,
Jan

amleto
24th August 2012, 15:38
try a typedef



typedef QMultiMap<QString, int> QMMap;
...
QMetaObject::invokeMethod(object,
"method",
Qt::BlockingQueuedConnection,
Q_ARG(QMMap, m_map));

hunsrus
24th August 2012, 17:51
Thanks for your reply!
I did it the way you explained now. Just to know: is there another possibility to do this?

amleto
24th August 2012, 18:24
I doubt it. Commas tend to break macros and since your attempt to fix it by using extra brackets didn't work (that's also the only inline solution that I know), the only other thing I could think of is typedef.

tarry1583
13th September 2012, 12:30
HI ,
Facing an issue for passing a pointer as QARG in invokeMethod :

I am calling the api void CAppManager::launchUrl(const int f_iXcoord,const int f_iYcoord,const int f_iHeight, const int f_iWidth,const QString f_cobjUrl,unsigned long *f_ulRenHandle,bool bSetupURL) as

QMetaObject::invokeMethod(this,"launchUrl",Qt::QueuedConnection,
Q_ARG(int,0),Q_ARG(int,0),Q_ARG(int,480),Q_ARG(int ,800),Q_ARG(QString,sSetUpURL),Q_ARG(unsigned long*,handle),Q_ARG(bool,true));

The issue seems to be with ARG f_ulRenHandle . As when the function had this argument only as pass by value and in InvokeMethod I had passed just Q_ARG(unsigned long,handle) instead of Q_ARG(unsigned long*,handle).It worked.
handle here has to be pointer or refrence as its getting modified in launchURL API .Here I am using pointer as we can't use Refrences with Q_ARG.Here invoke method is always returning 0.
I am initializing/declaring handle as follows :
unsigned long dummyHandle=0;
unsigned long * handle = &dummyHandle;
Please let me know what measure should i take to solve this issue ?

amleto
13th September 2012, 15:23
maybe you need to register 'unsigned int*' as a meta type?

tarry1583
13th September 2012, 20:46
NO i had tried with registering this datatype as well (unsigned long * ). But the code didn't work .
In Qt help , i had read " Q_ARG() takes a type name and a const reference of that type; Q_RETURN_ARG() takes a type name and a non-const reference." .Does this mean that the datatype has to be always constant with Q_ARG for invokeMethod , and we can never use a pointer and refrence for a variable passes as ARG which can be modified inside the api called like launchURL Api is modifying handle in the case i had mentioned .

amleto
13th September 2012, 23:39
If you just wish to change the int value, then you are not changing the pointer value... Passing a pointer for a method to change the pointed thing should be fine according to the doc quotes you have stated.

You do have an alternative, though:
"handle here has to be pointer or refrence as its getting modified in launchURL API .Here I am using pointer as we can't use Refrences with Q_ARG"
If you can change the launchURL API then you can use Q_RETURN_ARG and pass in an unsigned long - it will take it as a reference.