QML Loader: item.property binding is set only during loading, but is not linked
-
wrote on 4 Jun 2012, 06:50 last edited by
Hi,
I have the following loader:
@
Loader {
source: "myWindow.qml"
onLoaded: { item.title= myCppObject.title }
}
@
When myWindow is loaded the title is set, but when I change the title using myCppObject the title is not changed!@
class MyCppObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ Title NOTIFY TitleChanged)public:
MyCppObject (QObject* aParent = 0);
virtual ~MyCppObject ();void SetTitle(const QString & aTitle);
public slots:
const QString & Title();signals:
void TitleChanged();
private:
QString mTitle;
};
@@
void MyCppObject::SetTitle(const QString & aTitle)
{
mTitle = aTitle;
emit TitleChanged();
}const QString & MyCppObject::Title()
{
return Title;
}
@Before I haven't used the loader but just created all my windows at once during startup of my application. When I emitted a signal from c++ the QML object was notified and updated. When I use the loader and the onLoaded/item. construction the QML object isn't notified anymore when a change occurs.
-
wrote on 4 Jun 2012, 12:41 last edited by
Found the answer. Use Binding:
@
Binding {
target: loader.item
property: "model"
value: model
when: loader.status == Loader.Ready
}
@ -
wrote on 6 Jun 2012, 23:27 last edited by
Yes, the assignment form in your first post won't cause a binding. In QtQuick 1.x you can use a Binding element, and in QtQuick 2.0 you can either use a Binding element, or use the "initial property values" argument to the setSource function of the Loader, along with the Qt.binding() function, to generate a binding.
1/3