Results 1 to 2 of 2

Thread: QML - How to iterate through the types/properties available in a namespace

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QML - How to iterate through the types/properties available in a namespace

    I am using qmlRegisterUncreatableType() to register several C++ classes as QML types into a unique namespace. Each class comes with several properties.

    Qt Code:
    1. class Battery : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QString voltageStr READ voltageStr NOTIFY changed)
    5. Q_PROPERTY(QString currentStr READ currentStr NOTIFY changed)
    6. public:
    7. // ...
    8. };
    9.  
    10. class Load : public QObject
    11. {
    12. Q_OBJECT
    13. Q_PROPERTY(QString voltageStr READ voltageStr NOTIFY changed)
    14. Q_PROPERTY(QString currentStr READ currentStr NOTIFY changed)
    15. Q_PROPERTY(QString activePowerStr READ activePowerStr NOTIFY changed)
    16. Q_PROPERTY(QString reactivePowerStr READ reactivePowerStr NOTIFY changed)
    17. public:
    18. // ...
    19. };
    20.  
    21. ...
    22.  
    23. qmlRegisterUncreatableType<Battery>("MyDevice", 1,0, "Battery", "");
    24. qmlRegisterUncreatableType<Battery>("MyDevice", 1,0, "Load", "");
    To copy to clipboard, switch view to plain text mode 

    On the QML side I would like to iterate through the types available in the MyDevice namespace and iterate through the properties made available in each class to display them for example in a tree view. The content of the TreeView should adapt automatically depending on how the amount of registered classes and properties in each class.

    Has someone an idea how to iterate through the types available in a namespace and through the properties in a type available in a namespace in QML?

    The result should be something like:

    Qt Code:
    1. + MyDevice + Battery + Voltage + Value
    2. + Current + Value
    3. + Load + Voltage + Value
    4. + Current + Value
    5. + ActivePower + Value
    6. + ReactivePower + Value
    To copy to clipboard, switch view to plain text mode 

  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: QML - How to iterate through the types/properties available in a namespace

    Make a model in C++ that exposes that data.

    Cheers,
    _

Similar Threads

  1. Iterate through set of components
    By QTie in forum Newbie
    Replies: 2
    Last Post: 15th June 2011, 07:01
  2. Qt Designer Using non-standard types for properties in Designer
    By imsp_ftw in forum Qt Tools
    Replies: 0
    Last Post: 20th September 2010, 23:29
  3. Replies: 4
    Last Post: 10th December 2009, 16:37
  4. QVariant types support for custom properties
    By Dusdan in forum Qt Tools
    Replies: 9
    Last Post: 11th January 2006, 09:55

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.