Bindable dynamic properties on QObject or QQuickItem?



  • Is there a way to dinamically create a property on a QObject, QQuickItem or QQmlContext that will notify changes done by QML to C++?

    setProperty and setContextProperty do not notify changes done by QML to the c++ side.

    Using a static Q_PROPERTY with a QVariant map is the same, changes on "sub values" are not notified to the c++ side.

    I'm not sure about the QQmlProperty class, can this be used to create Q_PROPERTY(ies) or is it just an interface to existing Q_PROPERTIES?

    Thanks in advance


  • Moderators

    @Fede-Devi said in Bindable dynamic properties on QObject or QQuickItem?:

    Using a static Q_PROPERTY

    right, they are static. So they are created at compile time (MOC).
    Dynamic properties do not have a signal to trigger changes.

    You can create Q_PROPERTY properties of type QObject*. Those objects then can have properties which trigger changes.
    But at the end bindable properties always need to be 'static' and be known to the meta-object.

    What is your use-case to need dynamic properties?! i don't see how this might be useable in any way?!



  • What is your use-case to need dynamic properties?! i don't see how this might be useable in any way?!

    The application is completely model driven.

    The use case is exposing a single selected item of an item model with the same role names and same syntax of the item model and with "both-ways binding".

    something like:

    Textfield {
    text : itemModel.current.rolename;
    onTextChanged: itemModel.current.rolename = text;
    }

    Is there another way?

    I could notify the c++ manually with a Q_INVOKABLE but I would like to keep the syntax consistent.



  • Found a solution, QQmlPropertyMap


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.