×
Namespaces

Variants
Actions

How to use Q PROPERTY

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s): S60 5th Edition
Symbian
Article
Keywords: Q_PROPERTY
Created: skumar_rao (21 Nov 2010)
Last edited: hamishwillee (11 Oct 2012)


Overview

This macro PROPERTY() is used for declaring properties in classes that inherit QObject. Properties behave like class data members, but they have additional features accessible through the Meta-Object System.

How to use Q_PROPERTY()

Some times our application demands that we can access specific member variables of the QObject classes specifically those of the UI elements. This helps us in changing the CSS of the UI element and introducing animation to elements etc.

Qt provides more below types of operation on Q_PROPERTY

  • READ
  • WRITE
  • RESET
  • DESIGNABLE
  • SCRIPTABLE
  • STORED

The syntax is as follows:

    Q_PROPERTY(type name
READ getFunction
[WRITE setFunction]
[RESET resetFunction]
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool])

Of above all the most used ones are READ and WRITE

Example:

class MyNumberHolder : public QObject
{
Q_OBJECT
Q_PROPERTY( int number READ number WRITE setNumber )
public:
MyNumberHolder( int value = 0 );
~MyNumberHolder();
 
public:
int number() const;
void showNumber() const;
 
public slots:
void setNumber( int value );
 
private:
int m_value;
};

Refer to http://doc.qt.nokia.com/4.7/properties.html


More information : Q_PROPERTY

--skumar_rao 14:08, 21 November 2010 (UTC)

This page was last modified on 11 October 2012, at 04:17.
544 page views in the last 30 days.
×