Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Not getting onClicked in QML code

    QML and Qt Quick
    2
    3
    520
    Loading More Posts
    • 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.
    • Kevin Lussier
      Kevin Lussier last edited by

      Hi All.

      I have what is probably a simple problem but I can't figure out the answer. I have a very simple Qt Quick app that has a StackView in main.qml, a button in the .ui.qml file and an onClicked handler in the QML code file. The problem is, onClicked doesn't seem to be getting called.

      Any help would be appreciated.

      Thanks,
      Kevin

      main.qml

      import QtQuick 2.7
      import QtQuick.Window 2.0
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          title: qsTr("Where's My Click?")
          width: 120
          height: 60
          visible: true
      
          StackView {
              id: stack
              anchors.fill: parent
              initialItem: Page1Form {
                  anchors.fill: parent
              }
          }
      }
      

      Page1.qml

      import QtQuick 2.7
      
      Page1Form {
          pressMe.onClicked: {
              console.log("Button clicked.");
          }
      }
      

      Page1Form.ui.qml

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      Item {
          property alias pressMe: pressMe
          anchors.fill: parent
      
          Button {
              id: pressMe
              anchors.centerIn: parent
              text: qsTr("Press Me")
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • jpnurmi
        jpnurmi last edited by

        The onClicked signal handler is implemented in Page1, not in Page1Form. You meant to use Page1 as the initial item instead of Page1Form, right?

        initialItem: Page1 {
            anchors.fill: parent
        }
        
        1 Reply Last reply Reply Quote 2
        • Kevin Lussier
          Kevin Lussier last edited by

          I knew it had to be something simple. :-) Yes, that was it. Newbie here. Thanks for the quick response!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post