Results 1 to 8 of 8

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

Threaded View

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

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

    Assuming here's a class named QXXX inherited from QObject, how can i get the address of the property ["Abc"], any idea?


    Qt Code:
    1. class QABC : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(int Val READ Val WRITE setVal)
    5. public:
    6. QABC (QObject* parent = 0, int a = 987) : QObject(parent)
    7. {
    8. setVal(a);
    9. }
    10. ~QABC ()
    11. {
    12. }
    13. QABC (const QABC & rhs)
    14. {
    15. copyFrom(rhs);
    16. }
    17.  
    18. QABC & copyFrom(const QABC & rhs)
    19. {
    20. if(this == &rhs)
    21. return *this;
    22.  
    23. setVal(rhs._val);
    24.  
    25. return *this;
    26. }
    27.  
    28. QABC & operator = (const QABC & rhs)
    29. {
    30. return copyFrom(rhs);
    31. }
    32.  
    33. int Val() const { return _val; }
    34. void setVal( int val ) { _val = val; }
    35. private:
    36. int _val;
    37. };
    38. class QXXX : public QObject
    39. {
    40. Q_OBJECT
    41. Q_PROPERTY(QABC Abc READ Abc WRITE setAbc)
    42. public:
    43. QXXX(QObject* parent = 0, QABC a = QABC()) : QObject(parent)
    44. {
    45. setAbc(a);
    46. }
    47. ~QXXX()
    48. {
    49. }
    50. QXXX(const QXXX& rhs)
    51. {
    52. copyFrom(rhs);
    53. }
    54.  
    55. QXXX& copyFrom(const QXXX& rhs)
    56. {
    57. if(this == &rhs)
    58. return *this;
    59.  
    60. setAbc(rhs._Abc);
    61.  
    62. return *this;
    63. }
    64.  
    65. QXXX& operator = (const QXXX& rhs)
    66. {
    67. return copyFrom(rhs);
    68. }
    69.  
    70. QAbc Abc() const { return _Abc; }
    71. void setAbc( QAbc val ) { _Abc= val; }
    72. private:
    73. QABC _Abc;
    74. };
    To copy to clipboard, switch view to plain text mode 


    QXXX x;
    ...
    QObject * z = (QObject*)x;
    QObject* pointer = z ...?? ???? // to get (&QXXX::_Abc)
    I just only know the property name, it's 'Abc', can i get &z->_Abc?
    Last edited by HiJack; 27th August 2010 at 05:51.

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.