Results 1 to 3 of 3

Thread: QMetaEnum, QMetaProperty for dynamically added property

Hybrid View

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

    Default Re: QMetaEnum, QMetaProperty for dynamically added property

    Make SomeClass a QObject, create some mapping of enum name to meta object, e.g.
    Qt Code:
    1. QHash<QByteArray, QMetaObject*> EnumMap;
    2. EnumMap.insert("nameMyEnum", &SomeClass::staticMetaObject);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    20
    Thanked 28 Times in 27 Posts

    Default Re: QMetaEnum, QMetaProperty for dynamically added property

    Thanks for the suggestion.
    SomeClass is already a QObject derived class. Had to make it one to use Q_ENUMS, Q_DECLARE_METATYPE, qRegisterMetaType. However, there are a few of these SomeClass like classes. Currently runs into hundreds, and expected to grow further. Hardcoding for each one of these class into a hash will be too prone to break. I will have to introduce some kind of registration scheme for each class.
    Even that will end up being messy, given the fact that the enums types are int in qvariant. To get them to show some type I need to qRegisterMetaType for each of these. Given most of the enums of qt gui types are not registered, the code will be too prone to error as the author of a class may not introduce the qRegisterMetaType for each type.
    I wish there was a easier way out, like it is with static properties iteration and type classification. Too much to ask for, perhaps.

Similar Threads

  1. Replies: 8
    Last Post: 2nd February 2012, 19:52
  2. Replies: 5
    Last Post: 14th December 2011, 11:51
  3. Replies: 1
    Last Post: 28th October 2010, 22:36
  4. Connecting dynamically added properties
    By stefkeB in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2008, 15:19
  5. QMetaEnum
    By No-Nonsense in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2007, 15:15

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
  •  
Qt is a trademark of The Qt Company.