Can not read qml property from C++ when property under binding
---------- Mainitem.qml
Qt Code:
Switch view
Code:
import QtQuick 1.0
Item1 {
width: 100; height: 100
property string mrprefcolor: itemB.mypreferredcolor // Binding
ItemA1 {
id: square
Rectangle {
color: "red"
width: 10
height: 10
}
}
itemB {}
}
To copy to clipboard, switch view to plain text mode
---------- itemB.qml -------------
Qt Code:
Switch view
Code:
import QtQuick 1.0
property string mypreferredcolor: "red"
Item2 {
property length: 6
ItemB1 {
id: idc
Rectangle {
color: "red"
width: 10
height: 10
property rectype: 0
}
}
}
Hello
I'm trying to read the Mainitem.qml mypref property from C++, but it does not work. Is it because the property is binded?
I have tried the following (obj being the current *QObject):
metaObject->property(i).read(obj).toString(); // i is the index of mrprefcolor
and
= obj->property("mrprefcolor").toString();
Any thoughts
Thanks;
Mut.
Re: Can not read qml property from C++ when property under binding
Aside from this not being valid QML, why do you want to do that?
It is most often a bad ideal to access QML instantiated objects from C++.
Cheers,
_
Re: Can not read qml property from C++ when property under binding
Thanks for the reply. Yes, this is a bad qml, just put it there to illustrate my issue.
I need to access the QML properties from within C++ due to internal needs of my application.
Re: Can not read qml property from C++ when property under binding
If you can't get it to work you might have to reevaluate the internal needs of your application.
Would be very easy to bind to the property of a custom object.
Cheers,
_