[Interest] Setting propery values on Q_GADGET-based objects in qml possible?
Ola Røer Thorsen
ola at silentwings.no
Tue Jun 20 13:52:55 CEST 2017
Hi all,
I have a Q_GADGET-based class with properties that I instantiate in C++ and
expose to qml via QVariant in a list model. The class is registered to Qt
and Qml using Q_DECLARE_METATYPE,
qRegisterMetaType and qmlRegisterUncreatableType.
The properties are defined like this:
class MyGadget {
Q_GADGET
Q_PROPERTY(Type propName MEMBER propName)
public:
Type propName;
... etc
};
In QML I can read the properties just fine.
Now I'd like to take one of these gadget-objects in QML, modify some of
it's properties and then use it as an argument when calling a Q_INVOKABLE
c++ function.
In qml code this looks something like
property var theGadget // with a property .name = "Name"
function doStuff() {
var o = theGadget;
console.log("o.name"); // prints "Name"
o.name = "Some other name";
console.log("o.name"); // Still prints "Name" instead of "Some other
name"
backend.setNewGadget(o);
}
Trying to set any of the gadget object's properties does not have any
effect. The value of property "name" here is the same before and after the
assignment. Are Q_GADGET types to be considered read-only in QML, or am I
missing something else to make this work?
This is using Qt 5.9.0.
Best regards,
Ola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170620/322a1589/attachment.html>
More information about the Interest
mailing list