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. Individual function invokation
Forum Updated to NodeBB v4.3 + New Features

Individual function invokation

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 623 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.
  • S Offline
    S Offline
    svg_18
    wrote on last edited by
    #1

    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.
    @//MyButton.qml
    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()
    

    }
    @

    @//Main.qml
    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?

    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