PDA

View Full Version : [SOLVED] How to find out about "read only properties"



3dch
11th June 2009, 17:11
I try to populate a QObject descendant with the properties of another QObject descendant to have them identical (for example set a QTreeView to have the same property values as another QTreeView). Retrieving all properties poses no problems:



QStringList properties;

for(int i = 0; i < myTreeView->propertyCount(); ++i)
properties << QString::fromLatin1(myTreeView->property(i).name());


When applying the properties to another object I do verify that a property exists like this:



const QMetaObject* moOtherTreeView = otherTreeView->metaObject();

...

QByteArray propName = properties[ix].toLatin1();

// Make sure prop exists

if (moOtherTreeView->indexOfProperty(propName) < 0)
continue; // ignore this property

...

// Ok, apply property

otherTreeView->setProperty(propName, myTreeView->property(propName));


But unfortunately some of the properties are read only, which is reported by Qt in the debug output:



...

updatesEnabled
visible
minimized
QTreeView::setProperty: Property "minimized" invalid, read-only or does not exist
maximized
QTreeView::setProperty: Property "maximized" invalid, read-only or does not exist
fullScreen
QTreeView::setProperty: Property "fullScreen" invalid, read-only or does not exist
sizeHint

...


My question now is how to find out whether a property is read only or not?

thanks for any reply!
Ernst

SABROG
11th June 2009, 19:16
Try checkout return value
bool QObject::setProperty ( const char * name, const QVariant & value )

or


QMetaProperty QMetaObject::property ( int index ) const
bool QMetaProperty::isWritable () const

3dch
11th June 2009, 20:38
Thank you, SABROG

The isWritable() method perfectly solves my problem (next time I should have a deeper look at the Qt docs).

Regards
Ernst