[Qt-qml] setContextProperty and Property bindings

Schmidt dres-schmidt at t-online.de
Sun Oct 24 22:26:09 CEST 2010


Hi there,
I have a small class with one property. It is exposed from c++ to qml via setContextProperty(). 
But when i change The property in c++     and emit the NOTIFY signal the property is not changed in qml. I can set and read the value in qml perfectly.

In c++:
Class menu {
Q_PROPERTY(int d, ... NOTIFY dChanged())

Q_INVOKABLE int test { setD(1); return 1; }
...
Void setD(int val) { If (val!=m_d) { m_d=val; emit dChanged();}
...
}

In main():
Setcontextproperty(menu,,"menu");

and in qml:

TextInput {
focus: (menu.d == 1) 

MouseArea {
onClicked: test()
... if called dChanged() is emitted but ...focus does not change.

 If i write...
onClicked: menu.d = test()
   it works. 

So how do i set binding properly ?
Thank you,

Mike, 



More information about the Qt-qml mailing list