Results 1 to 8 of 8

Thread: How to Use Q_PROPERTY

  1. #1
    Join Date
    Jun 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to Use Q_PROPERTY

    Hi All,

    I am a newbie to QT and using QT4.1.1 on Ubuntu-linux. i have to port C#'s class porperties in QT. so i think Q_PROPERTY might be useful. so any one let me know how to use Q_PROPERTY and it is great help if i can get sample example.

    Thanks,
    Mitesh.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to Use Q_PROPERTY

    This should help you

  3. #3
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to Use Q_PROPERTY


  4. #4
    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: How to Use Q_PROPERTY

    And this.

  5. #5
    Join Date
    Jun 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to Use Q_PROPERTY

    Thanks All for quick reply.

    I have a one more question how can i use this property from other class which derive this class.

    like

    class NumberHolder : public QObject
    {
    Q_OBJECT
    Q_PROPERTY( int number READ number WRITE setNumber )

    public:
    NumberHolder( int value = 0 );
    ~NumberHolder();

    int number() const;

    void showNumber() const;

    public slots:
    void setNumber( int value );

    private:
    int m_value;
    };

    class DeriveClass : NumberHolder
    {
    private:
    int der_no;
    public:
    void assignProp()
    {
    der_no=NumberHolder.number; //HOW CAN I USE PROPERTY?
    }

    };

    Again Thanks for your help.

    Mitesh

  6. #6
    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: How to Use Q_PROPERTY

    In this case you just have to use the proper method:
    Qt Code:
    1. void assignProp()
    2. {
    3. der_no = number();
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jun 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to Use Q_PROPERTY

    Hi jacek,

    Thanks for quick reply,

    Thats right i can use method but then what is use of Q_PROPERTY? means i am missing some knowledge regarding Q_PROPERTY. I think that because of Q_PROPERTY macro one sholud not get the knowledge of class members and do get set of property defined in a class.

    Can you briefly give what is the exact use of Q_PROPERTY.

    Thanks,
    Mitesh..

  8. #8
    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: How to Use Q_PROPERTY

    Quote Originally Posted by mitesh_modi
    Can you briefly give what is the exact use of Q_PROPERTY.
    You can use QObject::property() and QObject::setProperty() to change the value of given property without knowing anything about the object.

    http://www.qtcentre.org/forum/f-newb...erty-1596.html

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.