Results 1 to 4 of 4

Thread: Q_ENUMS outside of the class?

  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Q_ENUMS outside of the class?

    Hi all!

    I want to use type safe enumeration like in C++11
    Qt Code:
    1. enum class Fruit
    2. {
    3. apple,
    4. orange,
    5. pear
    6. }
    To copy to clipboard, switch view to plain text mode 
    and use it in more (then one) classes
    Qt Code:
    1. class FruitCake
    2. {
    3. Fruit baseFruit; //use: baseFruit = Fruit::apple;
    4. }
    5. class Person
    6. {
    7. Fruit favoriteFruit; //use: favoriteFruit = Fruit::apple;
    8. }
    9.  
    10. if(john.favoriteFruit == myCake.baseFruit)
    11. john.eat(myCake)
    To copy to clipboard, switch view to plain text mode 
    OK, this can be done easily. But I want all the goodies that Q_ENUMS provides (The meta data of enum).
    How can i do that?

    Sorry for non-imaginative example

  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_ENUMS outside of the class?

    Q_ENUMS is processed by MOC, so it needs to be in a class that is QObject derived and has a Q_OBJECT marker.

    Cheers,
    _

  3. #3
    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_ENUMS outside of the class?

    Or you can try Q_GADGET on your enum class
    http://stackoverflow.com/questions/6...and-assignment

    Q_GADGET is only mentioned in passing in the QObjectvdocs. I suspect it will not well in the enum class.
    Last edited by ChrisW67; 11th October 2013 at 20:42.

  4. #4
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Q_ENUMS outside of the class?

    Thanks for your answers.
    I think that I will adjust my design and go with Qt style (QObject class with Q_ENUMS)

Similar Threads

  1. Q_ENUMS and Qt Style Sheet
    By Funtast in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2019, 20:56
  2. Q_ENUMS as property variant index
    By oosavu in forum Qt Quick
    Replies: 0
    Last Post: 9th April 2013, 06:07
  3. Q_ENUMS, QItemEditorFactory
    By Kunchok in forum Qt Programming
    Replies: 8
    Last Post: 21st January 2008, 12:20
  4. [SOLVED] Q_ENUMS from another class inside a plugin
    By desch in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2007, 15:44
  5. Q_ENUMS with QSA
    By Alex in forum Qt Programming
    Replies: 0
    Last Post: 24th May 2006, 01:36

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.