Results 1 to 8 of 8

Thread: How to get a pointer to a QObject's property ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    24
    Thanks
    5
    Qt products
    Qt4

    Default Re: How to get a pointer to a QObject's property ?

    Quote Originally Posted by hobbyist View Post
    Did you check the source? See QObject:roperty() and QMetaProperty::read() for the dirty details.
    Ya I do have seen back to QMetaProperty, but thers's no way to help me to get the member's address unless you modify the moc file. ( seems like anti-oop, hur? )
    I can enumerate the children list of one QObject object, but first I must set each member's parent, and second there's no one child pointer if the member's type is int, or QString, bool, etc. so I gave up this way.
    Another suggestion?
    Last edited by HiJack; 28th August 2010 at 06:54.

  2. #2
    Join Date
    Apr 2010
    Posts
    24
    Thanks
    5
    Qt products
    Qt4

    Default Re: How to get a pointer to a QObject's property ?

    solved manually. you guys.

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

    Default Re: How to get a pointer to a QObject's property ?

    Properties are not QObjects and don't have addresses. I think your whole concept is flawed because of a wrong assumption. If you'd like to get an address to a value of a property, it still wouldn't have worked as QVariant (which stores the value) is implicitly shared and thus the place in memory holding the value may vary in time (and you'd get a stale pointer). If you want to have a property which is QObject then that's another flaw as QVariant values are mutable and QObjects are not. You should only store a pointer to a QObject within a property.

    Qt Code:
    1. class PropVal : public QObject {
    2. Q_PROPERTY(int val READ ... WRITE ...);
    3. // ...
    4. };
    5.  
    6. class ABC : public QObject {
    7. Q_PROPERTY(QObject* abc READ ... WRITE ...);
    8. // ...
    9. };
    10. // ...
    11. ABC abc;
    12. PropVal *prop = qobject_cast<PropVal*>(qvariant_cast<QObject*>(abc.property("abc")));
    13. if(prop) {
    14. int val = prop->property("val").toInt();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 28th August 2010 at 11:04.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. C++ readonly property
    By yyiu002 in forum Newbie
    Replies: 16
    Last Post: 22nd June 2010, 10:26
  2. How to retrieve the device property?
    By vjsharma_30 in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2010, 18:24
  3. Replies: 1
    Last Post: 31st October 2007, 14:14
  4. enum property
    By illuzioner in forum Qt Tools
    Replies: 10
    Last Post: 22nd August 2006, 21:47
  5. AlignCenter property of the QTableView???
    By manhds in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2006, 09:35

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.