Namespaces
Variants
Actions
Revision as of 04:17, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to use Q PROPERTY

Jump to: navigation, search
Article Metadata

Compatibility
Platform(s): S60 5th Edition

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)

1228 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved