Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Properties in Qt and Symbian

From Wiki
Jump to: navigation, search

Needs-update.pngThis article needs to be updated: If you found this article useful, please fix the problems below then delete the {{ArticleNeedsUpdate}} template from the article to remove this warning.

Reasons: hamishwillee (15 Apr 2011)
While it remains largely accurate it states that Qt doesn't allow update of properties through IPC. Now out of date due to introduction of Publish & Subscribe.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 5th Edition
S60 5th Edition
Keywords: RProperty, Q_PROPERTY, Publish, Subscribe
Created: User:Technical writer 1 (09 Apr 2009)
Last edited: hamishwillee (11 Oct 2012)



This article provides a comparison of design/coding differences when using properties in Symbian and Qt.


Both Qt and S60 have a property system for easy storage and retrieval of data using standard APIs. S60 offers setting/retrieval of properties through the IPC mechanism, which is currently not available in Qt. In Qt, properties are intended to be class-specific variables which can be shared across classes by using the standard setter/getter functions without knowing class-specific functions to achieve the same.

Operation Symbian/S60 Qt
Property management system RProperty class Q_PROPERTY
Nature of properties Global variables which can be set and retrieved. Class-level variables that can be set and retrieved.
Change notifications Publish & Subscribe IPC mechanism enables interested threads/processes to know when a key changes. No publish/subscribe IPC in Qt. Within the same process, observer pattern or signal/slot mechanism can be used to get notifications (using QEvent).
Security It is possible restrict which applications can set/get the properties. No security restrictions possible.
Required class hierarchy None. Class in which properties are defined has to be a class derived from QObject.
Persistency The user-defined properties persist in the kernel until the OS reboots or the properties are deleted. Properties are member variables and values are lost when the object is destroyed.
Defining a property RProperty::Define() Q_PROPERTY(type name READ getFunction [WRITE setFunction] [RESET resetFunction] [DESIGNABLE bool] [SCRIRTABLE bool] [STORED bool])
Setting a property RProperty::Set() QObject::setProperty()
Getting a property RProperty::Get() QObject::property()
Deleting a property RProperty::Delete() (Property can be deleted only by the owning thread). None.
Subscribing to a property RProperty::Attach() and then RProperty::Subscribe(). The subscriber is an Active Object whose RunL() will be invoked when change notifications are received. QEvent::event of QObject (from which the class is derived) is called whenever a property changes. Then, a signal can be emitted by the class which owns the property. Interested parties can catch the signal and do the necessary operation (no IPC available). Alternatively, the interested applications can register as observers and get notified whenever the properties change.


This solution describes how to create a property, get values, set values and usage of signal/slot mechanism used to inform other classes of any change in the property.

This example has 2 classes, MyProperty (which needs to be compiled first) and MyPropertyChanger which is an application dependent on MyProperty.dll. MyPropertyChanger class has 2 buttons: Hello and Exit. When the Hello button is pressed, it increments and sets the property value in MyProperty. A notification is received in MyPropertyChanger through signal slot mechanism when the property value changes and the new value is displayed in the text box.

Method I

  class MyProperty : public QObject
// Defining a property
Q_PROPERTY( Priority priority READ priority WRITE setPriority )
Q_ENUMS( Priority )
enum Priority { High = 1, Low, VeryHigh, VeryLow };
// Property can be set either through this function
// or base class function setProperty()
void setPriority( Priority value ) { priority = value; }
// Property can be retrieved either through this function
// or base class function property()
Priority priority() const { return priority; }
// Any change in property value is notified through this function
// This function is overridden function of QEvent::event()
bool MyProperty::event( QEvent* e );
// emitted when property changes
void propertyChanged(QByteArray name, int value);
public slots:
// Sets the property
void settingProperty();
// Property that needs to be set
Priority priority;
int val;
void MyProperty::settingProperty()
if(val > VeryLow) {
val = High;
// Using setProperty from QObject
setProperty("Priority", val);
// Event handler for property change event.
// Will be called whenever the value of a property is changed
bool MyProperty::event( QEvent* e )
// Check if event is for property change
if( e->type() == QEvent::DynamicPropertyChange ) {
// Check if the event is for property of our interest
QDynamicPropertyChangeEvent event( "Priority" );
if( event.propertyName() == "Priority" ) {
// Gets the property value and emits a signal
// with the name and value of property
emit propertyChanged( event.propertyName(),
property( "Priority" ).toInt() );
return true;
return false;
// Class that gets notified when a property is changed
// through signal/slot mechanism
class MyPropertyChanger : public QWidget
MyPropertyChanger( QWidget *parent = 0 );
public slots:
// Function to show the property value
void ShowHelloText( QByteArray name, int changedValue );
Ui::MyPropertyChangerClass ui;
MyProperty* prop;
MyPropertyChanger::MyPropertyChanger( QWidget *parent )
:QWidget( parent )
ui.setupUi( this );
// Property object creation
prop = new MyProperty();
// When a button is clicked call a function to set the property
QObject::connect(ui.hello, SIGNAL(clicked()), prop, SLOT(SettingProperty()));
// When property changed signal is emitted handle it
QObject::connect( prop, SIGNAL( propertyChanged( QByteArray, int ) ),
this, SLOT( ShowHelloText( QByteArray, int ) ) );
delete prop;
void MyPropertyChanger::ShowHelloText( QByteArray name, int changedValue )
QString s = QString::number( changedValue, 10 );
ui.label->setText( s );

Sample application

File:Property S60

This page was last modified on 11 October 2012, at 01:18.
68 page views in the last 30 days.