Results 1 to 3 of 3

Thread: Macros in the slot section

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Macros in the slot section

    Hello,
    I would like to use a macro in the slot section but the moc preprocessor encapsulates it BEFORE the C++ preprocessor processes it, which leads to an error. How to cope with this issue?

    Macro function:
    Qt Code:
    1. #define SetFloatSlotMacro(name, arg) \
    2. void Set##name(QString arg) {this->Set##name(arg.toFloat());}; \
    3. void Set##name(float arg)
    To copy to clipboard, switch view to plain text mode 
    Resulting code in moc generated file:
    Qt Code:
    1. case 4: { int _r = SetFloatSlotMacro((*reinterpret_cast< IdleToWalk(*)>(_a[1])),(*reinterpret_cast< speed(*)>(_a[2])));
    2. if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; } break;
    To copy to clipboard, switch view to plain text mode 
    Error at compile time:
    Qt Code:
    1. moc_Avatar.cpp:94:1: error: pasting "Set" and "(" does not give a valid preprocessing token
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Macros in the slot section

    probably that can be achieved by adding a pre-processing step into the build process with qmake: qmake-environment-reference.html#customizing-makefile-output
    Haven't tried myself yet, though.

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Macros in the slot section

    Quote Originally Posted by caduel View Post
    probably that can be achieved by adding a pre-processing step into the build process with qmake: qmake-environment-reference.html#customizing-makefile-output
    Haven't tried myself yet, though.
    Hmmm, seems not to be easy, I suspect (hope) there is an easier way to cope with this issue...

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Highlighting selected section on QDateTimeEdit
    By Yorma in forum Qt Programming
    Replies: 4
    Last Post: 3rd May 2013, 12:03
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44

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.