qt - QML dictionary (jsobject, var) sub-properties notify -
is possible raise notify-method of var
/variant
/object
/ (etc.) variables automatically during updating?
suppose have:
property var objects: {'obj1': 'unnamed', 'obj2': 'unnamed'}
next have binding in, example, text:
text { text: objects.obj1 ontextchanged: objects.obj1 = text }
in ontextchanged
want raise notify signal of objects
variable update everywhere.
hm, if not mistaken, qml generates onobjectschanged
signal handler objects
not emitted when change objects
internally, , due qml brilliant design, cannot emit objectschanged()
manually, expected automatically emit, except doesn't. emits when property reassigned object.
you cannot create signal js object, since requires qobject
derived class signals , therefore notifications , bindings.
you can force emit objectschanged()
reassigning objects
property new object new value obj1 , old value of obj2, force second text element update , show new value. not elegant, if need use js object, valid solution. otherwise have use qtobject
element , qml properties obj1/2
property var objects: {'obj1': 'unnamed', 'obj2': 'unnamed'} column { spacing: 30 textedit { text: objects.obj1 ontextchanged: { objects = {'obj1': text, 'obj2': objects.obj2} } } text { text: objects.obj1 } }
another possible solution not rely on notifications objects
, use proxy property controller it.
property var objects: {'obj1': 'unnamed', 'obj2': 'unnamed'} property string obj1: objects.obj1 onobj1changed: objects.obj1 = obj1
this way don't use objects
@ all, except storing data it, use obj1
property instead, , every time changed write changed objects
without reassigning entire objects in first solution.
but unless need js objects, i'd recommend scrapping , using more qml friendly data representation..
Comments
Post a Comment