Results 1 to 3 of 3

Thread: Expose field of a sub-class to QML

  1. #1
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Expose field of a sub-class to QML

    Hi,

    I have to expose into a QML widget fields from a set of nested classes like in the follows example:


    Qt Code:
    1. class A : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QString name READ getName)
    5.  
    6. public:
    7. ...
    8. QString getName()
    9.  
    10. private:
    11. QString _name;
    12.  
    13. }
    14.  
    15.  
    16. class B : public A
    17. {
    18. Q_OBJECT
    19. Q_PROPERTY(int value READ getValue)
    20.  
    21. public:
    22. B(int val);
    23. int getValue();
    24.  
    25. private:
    26. int _value;
    27. }
    28.  
    29.  
    30. // in another c
    31. Q_INVOKABLE QObject * getObjectOfTypeB()
    32. {
    33. return new B(1);
    34. }
    To copy to clipboard, switch view to plain text mode 

    in QML:
    Qt Code:
    1. var tmp = myModel.getObjectOfTypeB();
    2.  
    3. tmp.name // works
    4. tmp.value // undefined
    To copy to clipboard, switch view to plain text mode 

    The filed from the top class works, while the field form the sub-class B is undefined.
    What's wrong?

    Thank you

  2. #2
    Join Date
    Sep 2008
    Location
    Munich
    Posts
    32
    Thanked 8 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expose field of a sub-class to QML

    So far, everything looks good for me. Can you show the code where myModel is registered and instantiated?

  3. #3
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Expose field of a sub-class to QML

    Sorry code was wrong.
    In original cosa is missing a "Q_OBJECT" macro.

Similar Threads

  1. Expose enums with webkit
    By frank100 in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2014, 02:16
  2. How to expose QMap to QML?
    By fonzi337 in forum Qt Quick
    Replies: 8
    Last Post: 9th September 2013, 15:00
  3. Expose C++ enum to QML
    By OnlyK in forum Qt Quick
    Replies: 3
    Last Post: 3rd August 2011, 06:43
  4. Replies: 1
    Last Post: 23rd June 2011, 23:09
  5. How to expose c++ plugins to Qml/QtCreator
    By dwalker0044 in forum Qt Quick
    Replies: 8
    Last Post: 21st June 2011, 08:39

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.