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. Not getting onClicked in QML code
Forum Update on Monday, May 27th 2025

Not getting onClicked in QML code

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 665 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.
  • K Offline
    K Offline
    Kevin Lussier
    wrote on 10 Aug 2016, 05:04 last edited by
    #1

    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
    0
    • J Offline
      J Offline
      jpnurmi
      wrote on 10 Aug 2016, 15:36 last edited by
      #2

      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
      2
      • K Offline
        K Offline
        Kevin Lussier
        wrote on 10 Aug 2016, 17:13 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        10 Aug 2016, 05:04

        • 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