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 button clicked not triggered in *.qml file
Forum Updated to NodeBB v4.3 + New Features

qml button clicked not triggered in *.qml file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 775 Views 2 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.
  • J Offline
    J Offline
    James A
    wrote on last edited by James A
    #1

    I created a simple Qt quick UI with button , where the Ui is seperated into Test.qml and TestForm.ui.qml files. I have added the button.onClicked function in the Test.qml file , but the onclicked function is not getting triggered. When I tried to move the onClicked function to TestForm.ui.qml file it is working

    How to fix this issue ?

    I have added the code which I tried

    main.qml

    import QtQuick 2.11
    import QtQuick.Window 2.11
    import QtQuick.Controls 2.15

    Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    StackView {
        id: stackView
        anchors.fill: parent
        initialItem: "TestForm.ui.qml"
    }
    

    }

    Test.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.15

    TestForm {

    anchors.fill:  parent
    
    button.onClicked: {
        console.log("button clicked")
    }
    

    }

    TestForm.ui.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.15

    Item {
    width: 400
    height: 400
    property alias button: button

    Button {
        id: button
        x: 130
        y: 135
        text: qsTr("Button")
    }
    

    }

    ODБOïO 1 Reply Last reply
    0
    • J James A

      I created a simple Qt quick UI with button , where the Ui is seperated into Test.qml and TestForm.ui.qml files. I have added the button.onClicked function in the Test.qml file , but the onclicked function is not getting triggered. When I tried to move the onClicked function to TestForm.ui.qml file it is working

      How to fix this issue ?

      I have added the code which I tried

      main.qml

      import QtQuick 2.11
      import QtQuick.Window 2.11
      import QtQuick.Controls 2.15

      Window {
      width: 640
      height: 480
      visible: true
      title: qsTr("Hello World")

      StackView {
          id: stackView
          anchors.fill: parent
          initialItem: "TestForm.ui.qml"
      }
      

      }

      Test.qml

      import QtQuick 2.4
      import QtQuick.Controls 2.15

      TestForm {

      anchors.fill:  parent
      
      button.onClicked: {
          console.log("button clicked")
      }
      

      }

      TestForm.ui.qml

      import QtQuick 2.4
      import QtQuick.Controls 2.15

      Item {
      width: 400
      height: 400
      property alias button: button

      Button {
          id: button
          x: 130
          y: 135
          text: qsTr("Button")
      }
      

      }

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi
      @James-A said in qml button clicked not triggered in *.qml file:

      initialItem: "TestForm.ui.qml"

      should be initialItem: "Test.qml"

      1 Reply Last reply
      1
      • J Offline
        J Offline
        James A
        wrote on last edited by
        #3

        Thank you , This solved the issue

        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