Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Bindable dynamic properties on QObject or QQuickItem?
Qt 6.11 is out! See what's new in the release blog

Bindable dynamic properties on QObject or QQuickItem?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fede Devi
    wrote on last edited by
    #1

    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

    raven-worxR 1 Reply Last reply
    0
    • F Offline
      F Offline
      Fede Devi
      wrote on last edited by
      #4

      Found a solution, QQmlPropertyMap

      1 Reply Last reply
      0
      • F Fede Devi

        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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #2

        @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?!

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        F 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @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?!

          F Offline
          F Offline
          Fede Devi
          wrote on last edited by Fede Devi
          #3

          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.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Fede Devi
            wrote on last edited by
            #4

            Found a solution, QQmlPropertyMap

            1 Reply Last reply
            0
            • strahlexS Offline
              strahlexS Offline
              strahlex
              wrote on last edited by
              #5

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

              QQmlPropertyMap

              In case your solution is not enough you can check out my write-up about this topic: https://machinekoder.com/creating-qml-properties-dynamically-runtime-c/

              I have to take a look at QQmlPropertyMap as well.

              Feel free to check out my website machinekoder.com
              and my pet projects Intellicute and QtQuickVcp

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved