Results 1 to 8 of 8

Thread: passing QMultiMap to Q_ARG?

  1. #1
    Join Date
    Jun 2008
    Posts
    26
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default passing QMultiMap to Q_ARG?

    Hi everybody,

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

    Qt Code:
    1. QMultiMap<QString, int>
    To copy to clipboard, switch view to plain text mode 

    using

    Qt Code:
    1. QMetaObject::invokeMethod(object,
    2. "method",
    3. Qt::BlockingQueuedConnection,
    4. Q_ARG(QMultiMap<QString, int>, m_map));
    To copy to clipboard, switch view to plain text mode 

    where m_map is defined as:
    Qt Code:
    1. QMultiMap<QString, int> m_map;
    To copy to clipboard, switch view to plain text mode 

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

    Surrounding the QMultiMap as follows:
    Qt Code:
    1. Q_ARG((QMultiMap<QString, int>), m_map));
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing QMultiMap to Q_ARG?

    try a typedef

    Qt Code:
    1. typedef QMultiMap<QString, int> QMMap;
    2. ...
    3. QMetaObject::invokeMethod(object,
    4. "method",
    5. Qt::BlockingQueuedConnection,
    6. Q_ARG(QMMap, m_map));
    To copy to clipboard, switch view to plain text mode 
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. The following user says thank you to amleto for this useful post:

    hunsrus (30th August 2012)

  4. #3
    Join Date
    Jun 2008
    Posts
    26
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: passing QMultiMap to Q_ARG?

    Thanks for your reply!
    I did it the way you explained now. Just to know: is there another possibility to do this?

  5. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing QMultiMap to Q_ARG?

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. The following user says thank you to amleto for this useful post:

    hunsrus (30th August 2012)

  7. #5

    Default Re: passing QMultiMap to Q_ARG?

    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::Que uedConnection,
    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 ?

  8. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing QMultiMap to Q_ARG?

    maybe you need to register 'unsigned int*' as a meta type?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #7

    Default Re: passing QMultiMap to Q_ARG?

    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 .

  10. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing QMultiMap to Q_ARG?

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QMultiMap And QDataStream
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2011, 10:50
  2. Q_ARG with C++ reference types
    By RichardNixon in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2008, 09:11
  3. Passing signals
    By gruszczy in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2008, 14:19
  4. Delete auto pointer from QMultiMap
    By phillip_Qt in forum Qt Programming
    Replies: 5
    Last Post: 3rd December 2007, 17:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.