Results 1 to 8 of 8

Thread: Examples for runtime introspection?

  1. #1
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Examples for runtime introspection?

    Hello,

    Are there any examples showing how to use Qt's runtime introspection capability. I was really glad to see this capability. My opinion of Qt keeps getting better. It's much more than just a GUI library ... there are many framework development aspects as well.

    I've begun looking at these classes:
    QMetaObject
    QMetaProperty
    QMetaMethod
    QVariant
    ...
    Any pointers greatly appreciated.

    Cheers,
    Ben

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Examples for runtime introspection?

    What do you want to achieve exactly? AFAIR there has been a thread about introspection recently here. Maybe trying to find it could return valuable results for you.

  3. #3
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Examples for runtime introspection?

    I asked a question recently if there *was* runtime introspection capability with Qt. You replied (I think) referring me to QMetaObject.

    What I need ... I need the capability to discover the interface of a class (attributes and methods ... their numbers, types, values) during runtime. This sort of thing as you know is supported in Java ... just trying to leverage Qt to provide similar capability in C++.

    I've been looking at the Qt documentation and header files ... but need some guidance in the form of examples ... since the documentation is a bit terse. I haven't found any ... in installation examples, book examples, FAQs, Qt Center query, and Google. I've made some progress ... but am having trouble declaring the properties for the introspection mechanism.

  4. #4
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Examples for runtime introspection?

    I think I figured out what I was doing wrong ... was putting quotes around the fields for the Q_PROPERTY entries. I'd still like to see a more rich example. It might be something I could add in a Wiki area ... if there is one ... when I get my hands wrapped around it.

    Qt Code:
    1. #ifndef _MY_CLASS_H_
    2. #define _MY_CLASS_H_
    3.  
    4. #include <QMetaClassInfo>
    5.  
    6. class cMyClass : public QObject
    7. {
    8. Q_OBJECT
    9. Q_CLASSINFO("author", "John Doe")
    10. Q_CLASSINFO("url", "http://doc.trolltech.com/")
    11. Q_PROPERTY(int mData
    12. READ getData()
    13. WRITE setData())
    14. public:
    15.  
    16. cMyClass() :
    17. mData(0) {}
    18.  
    19. int const getData() { return mData; }
    20.  
    21. void setData(int data) { mData = data; }
    22. int mData;
    23. }; // cMyClass
    24.  
    25. #endif // _MY_CLASS_H_
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Examples for runtime introspection?

    Quote Originally Posted by brcain View Post
    It might be something I could add in a Wiki area ...
    You can always write an article in our wiki.

  6. #6
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Examples for runtime introspection?

    I still consider my self a bit of a novice ... little hesitant to write an article ... but maybe I shouldn't be. I do want to get to a point that I can be more of a contributor ... don't want to only be asking questions. I am ramping up though. I have quite a few years of dev experience ... just not Qt.

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Examples for runtime introspection?

    Quote Originally Posted by brcain View Post
    Qt Code:
    1. #ifndef _MY_CLASS_H_
    2. #define _MY_CLASS_H_
    3.  
    4. #include <QMetaClassInfo>
    5.  
    6. class cMyClass : public QObject
    7. {
    8. Q_OBJECT
    9. Q_CLASSINFO("author", "John Doe")
    10. Q_CLASSINFO("url", "http://doc.trolltech.com/")
    11. Q_PROPERTY(int mData
    12. READ getData()
    13. WRITE setData())
    14. public:
    15.  
    16. cMyClass() :
    17. mData(0) {}
    18.  
    19. int const getData() { return mData; }
    20.  
    21. void setData(int data) { mData = data; }
    22. int mData;
    23. }; // cMyClass
    24.  
    25. #endif // _MY_CLASS_H_
    To copy to clipboard, switch view to plain text mode 
    I'm quite sure you don't need parentheses in property declaration... And it might even confuse qmake...

    You may also consider using the "dynamic" properties introduced in Qt 4.2.
    Current Qt projects : QCodeEdit, RotiDeCode

  8. The following user says thank you to fullmetalcoder for this useful post:

    brcain (21st September 2006)

  9. #8
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Examples for runtime introspection?

    Thanks ... didn't notice the parens. I will look for the 4.2 features. I'm currently using 4.1.4 ... hope to switch to 4.2 soon.

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.