Individual function invokation

  • Hello,

    Does anyone know how QML objects invoke C++ functions individually? Now, that's very general, so I'll try to explain what I mean with an example.
    For example, I have a custom qml component that I use as a button element. For it I call a function from C++ that updates a counter attribute in a C++ class which keeps track of how many times the button was pressed and upon changing that value, a text on the button is also changed to display the new value.
    Rectangle {
    MouseArea {
    id: marea
    anchors.fill: parent
    //myObject is an exposed C++ class
    //ButtonPressed() is an invokable function that increments the button counter
    onClicked: myObject.ButtonPressed()

      Text {
       id: bText
      //buttonCounterChanged is emitted from my C++ class 
      onButtonCounterChanged: bText.text = myObject.getButtonCounter()


    Rectangle {
    id: container
    Component {
    id: mydelegate
    MyButton {}

       ListView {
              id: buttonView
              model: ListModel { id: buttonModel }
              delegate: mydelegate


    When I run my app, I have created some number of buttons and by pressing each of them the number shown is the individual number of presses for each button.
    I am trying to figure out how does QML keep track of the individual number of button presses in this case - since my component is a delegate. Do the buttons react to different signals?

Log in to reply

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