Results 1 to 4 of 4

Thread: Q_arg

  1. #1
    Join Date
    Nov 2015
    Posts
    67

    Default Q_arg

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_arg

    That doesn't make any sense.

    Maybe describe what you want to do?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Q_arg

    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Q_arg

    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.

Similar Threads

  1. passing QMultiMap to Q_ARG?
    By hunsrus in forum Qt Programming
    Replies: 7
    Last Post: 13th September 2012, 22:39
  2. Q_ARG with C++ reference types
    By RichardNixon in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2008, 09:11

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.