Results 1 to 3 of 3

Thread: Q_ENUMS on C-style global enums

  1. #1
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Q_ENUMS on C-style global enums

    Hi

    I'm using external headers (C-style) that have enums outside classes.

    I was hoping to use the Q_ENUMS to get the strings directly, but haven't found a solution.

    As it's C and no C++, the enums are global.

    I cannot seem to find a way to use Q_ENUMS for global enums outside a namespace, or does anyone know a way to make it work?

    cheers,
    Leif

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q_ENUMS on C-style global enums

    I'm afraid there is simply no way to do that. Q_ENUMS registers enums to the meta-object of that particular class. There is no meta-object for the global namespace...
    In addition, the class defining the enum has to inherit QObject.
    In fact, you can use Q_GADGET together with Q_ENUMS in a non-QObject subclass... but again, I don't think there is any solution to your problem.
    J-P Nurmi

  3. #3
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Smile Re: Q_ENUMS on C-style global enums

    Thanks for the reply.

    I found a solution, by modifing the header that contained the enums with something similar to this:

    Qt Code:
    1. #ifdef QT
    2. class MyQtAppEnums : public QObject
    3. {
    4. Q_OBJECT
    5. Q_ENUMS(myenum)
    6. public:
    7. MyQtAppEnums (void) {};
    8.  
    9. #endif
    10.  
    11. myenum {
    12. the = (1<<8),
    13. number,
    14. is,
    15. fortytwo = 42
    16. };
    17.  
    18. #ifdef QT
    19. }
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    The above might not be 100%, but shows at least how a c style header can be kept intact for a c-compiler and make the enums a bit more qt-friendly when using moc + a c++ compiler.

    thanks,
    leif

  4. The following user says thank you to luf for this useful post:

    wa_laan (7th May 2012)

Tags for this Thread

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.