I've got a subclass of QObject
and use setProperty
to add dynamic properties to it in C++.
Now I want to use them in QML. I would have expected to be able to access them like properties defined with Q_PROPERTY
but that only yields undefined
.
It is currently not possible. As a possible workaround you can expose from your C++ object to QML some helper function to get the value of a dynamic property:
TestObject::TestObject(QObject *parent) : QObject(parent)
{
setProperty("test","testvalue");
}
QVariant TestObject::getDynamicProperty(const QString &name)
{
return property(name.toLatin1());
}
and so you will be able to get its value from QML:
TestObject {
Component.onCompleted: console.log(getDynamicProperty("test"));
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments