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. QML - signals for properties of nested objets
Forum Updated to NodeBB v4.3 + New Features

QML - signals for properties of nested objets

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 478 Views 3 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.
  • R Offline
    R Offline
    Richard Buchmann
    wrote on last edited by
    #1

    Re: QML - signals for nested properties

    In fact, I would like to read a JSON file and store it into a variable.
    Ideally, components will read/write/connect to the nested properties.

    I fail to connect to signals of nested properties.
    I tried several approaches:

        property var test: { "a": "a value", "nested": { "inner": 5 } }
        // property alias aliasTestA: test.a  // does not compile: Invalid alias reference. Unable to find id "test"
        property var bindingTestA: test.a
        property var bindingTestNestedInner: test.nested.inner
    
        Connections {
            target: item
            function onTestChanged() {
                console.debug("onTestChanged", test)
            }
        }
    
        Connections {
            target: test
            function onAChanged() {
                console.debug("test.onFooChanged", test.a)
            }
        }
    
        Connections {
            target: test.nested
            function onInnerChanged() {
                console.debug("test.nested.onInnerChanged", test.nested.inner)
            }
        }
    
        // onAliasTestAChanged: console.debug("onAliasTestAChanged", test.a)
        onBindingTestAChanged: console.debug("onBindingTestAChanged", test.a)
        onBindingTestNestedInnerChanged: console.debug("onBindingTestNestedInnerChanged", test.nested.inner)
    
        Component.onCompleted: {
            test.nested.inner = 6;
            test.nested = { "inner": 7}
            test.a = "baz"
            test = { "a": "arg", "nested": { "inner": 8 } }
        }
    

    I got:

    QML Connections: Detected function "onInnerChanged" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.
    onBindingTestAChanged a value
    onBindingTestNestedInnerChanged 5
    onBindingTestAChanged arg
    onBindingTestNestedInnerChanged 8
    onTestChanged [object Object]
    

    Adding binding for each property is not really simple and time effective.
    It also miss a change: inner = 7.

    Is there any tips to connect to signals in an effective way?

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      An object must be QObject based to emit signals, whether property changes or otherwise.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      R 1 Reply Last reply
      0
      • jeremy_kJ jeremy_k

        An object must be QObject based to emit signals, whether property changes or otherwise.

        R Offline
        R Offline
        Richard Buchmann
        wrote on last edited by
        #3

        @jeremy_k Ok right!

        Is there any way to convert this json object into a QObject with dynamic properties and signals?

        1 Reply Last reply
        0
        • Marko StankeM Offline
          Marko StankeM Offline
          Marko Stanke
          wrote on last edited by Marko Stanke
          #4

          I think the only way for you is to use a QtObject and declare properties for it:

          property QtObject test: QtObject {
              property string a;
              etc...
          }
          
          jeremy_kJ 1 Reply Last reply
          0
          • Marko StankeM Marko Stanke

            I think the only way for you is to use a QtObject and declare properties for it:

            property QtObject test: QtObject {
                property string a;
                etc...
            }
            
            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            @Marko-Stanke said in QML - signals for properties of nested objets:

            I think the only way for you is to use a QtObject and declare properties for it:

            property QtObject test: QtObject {
                property string a;
                etc...
            }
            

            Yes, QML's QtObject is a QObject. Item, Rectangle, and most instantiable types know to the QML engine would also work to host properties. If you don't need any of their extra capabilities, then QtObject is the leanest QML language option.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0

            • Login

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