PDA

View Full Version : Can not read qml property from C++ when property under binding



mut
1st April 2016, 03:07
---------- Mainitem.qml
Qt Code:
Switch view


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


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.

anda_skoa
1st April 2016, 08:49
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,
_

mut
1st April 2016, 21:08
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.

anda_skoa
2nd April 2016, 11:46
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,
_