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 property binding not updating
Forum Update on Monday, May 27th 2025

QML property binding not updating

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 4.3k Views
  • 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.
  • B Offline
    B Offline
    bluestreak
    wrote on 19 Jul 2012, 16:11 last edited by
    #1

    I am continuously getting data for my application as it runs, but I am having a bit of trouble displaying the data once I have read it in and stored it in a map. When I try to display the data in the QML, it simply displays zero, despite the fact that I can see it updating in the application output.

    I access the value in QML using property bindings (I was under the impression that these led headingSensor to be updated whenever carData.headingSensor changed???):
    @
    property int headingSensor: carData.headingSensor
    Text { text: "Heading: " + headingSensor }
    @
    In my data class I have:
    @
    Q_PROPERTY(int headingSensor READ getHeadingSensor NOTIFY headingSensorChanged)
    int headingSensor;
    @
    In the c++ implementation I originally had:
    @
    int data::getHeadingSensor(){
    return data.value(heading)[headingSensorReading];
    }
    @

    Where it returns the value in the map which is being updated with the incoming information. This I realized, probably doesn’t work, because the property is dependent upon the headingSensor variable, which is itself not being updated despite the correct value being returned. So, I thought if I changed it to update the headingSensor value and return that it might work. So in my data aquisition logic I wrote a method to update the variables as well.
    @
    data.insert(key, value);
    updateVariables();
    }
    }
    }
    void data::updateVariables(){
    headingSensor = data.value(heading)[headingSensorReading];
    }
    int data::getHeadingSensor(){
    return headingSensor;
    }
    @

    While this led to the headingSensor variable being updated in addition to the value in the map, the correct value is still not displayed in the QML display. It simply displays 0 (its default value when it is initially displayed since it has not gotten a value from incoming data yet).

    So, I am wondering, how can I get the value of sensorHeading displayed in the QML to update as the value of it and/or the value in the map changes in c++? Do I need to do something like
    @
    Connections {
    target: carData
    onSensorHeadingChanged: updateValues
    }
    @
    ????
    EDIT: Trying something like this, the onSensorHeadingChanged never fires. I am not sure why, since the value of sensorHeading clearly changes as I watch it in the application output
    @
    Connections{
    target: carData
    onHeadingSensorChanged: console.log("It's noting the change!")
    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      trollixx
      wrote on 19 Jul 2012, 21:54 last edited by
      #2

      Don't you forget to emit headingSensorChanged signal, when headingSensor value changes?

      Oleg

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bluestreak
        wrote on 19 Jul 2012, 22:14 last edited by
        #3

        Ah! I am a fool! Thank you so much. I was so used to writing elements that had getters and setters (which emitted the Changed signal), that when I was writing this where the socket updates the information, I did not think to put in the emit signal. Thanks a million!

        1 Reply Last reply
        0

        1/3

        19 Jul 2012, 16:11

        • Login

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