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. QT Quick no events ("onClicked" or "onCurrentIndexChanged") work - what I am doing wrong?

QT Quick no events ("onClicked" or "onCurrentIndexChanged") work - what I am doing wrong?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qtquick
10 Posts 3 Posters 2.7k 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.
  • S Offline
    S Offline
    sm-a
    wrote on 2 Mar 2019, 14:29 last edited by sm-a 3 Mar 2019, 12:56
    #1

    I am new to QT Quick and have a problem what I can't solve with Google search. I hope I get here help.

    My problem: I have created a QT Quick App from the template "QT Quick Application Stack". But no "onClicked" event or "onCurrentIndexChanged" event will be executed. What I am doing wrong?

    Test.qml

    import QtQuick 2.9
    import QtQuick.Dialogs 1.2
    
    TestForm {
        button.onClicked: {
            dialog.open()
        }
        countryComboBox.onCurrentIndexChanged: {
            dialog.open()
        }
    
        MessageDialog {
                    id: dialog
                    title: qsTr("this is a test")
                    text: qsTr("test ok")
                    
                    function show(caption) {
                        dialog.open();
                   }
        }
    }
    
    

    TestForm.ui.qml

    import QtQuick 2.9
    import QtQuick.Controls 2.2
    
    Page {
        width: 600
        height: 400
        property alias button: button
        property alias countryComboBox: countryComboBox
    
        title: qsTr("Country select")
    
        ComboBox {
            currentIndex: 0
            id: countryComboBox
            x: 16
            y: 12
    
            model: ["Banana", "APPLE"]
        }
    
        Button {
            id: button
            x: 132
            y: 102
            text: qsTr("Button")
        }
    }
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      gfxx
      wrote on 3 Mar 2019, 05:35 last edited by
      #2

      on designer inside ui.qml file ... design mode ... hover the button .... right click on mouse button ... choose "go to implementation".

      without these passages your code not work. After these you find in your qml file

                  button.onClicked: {
                console.log("log completed")
      }
      

      regards

      I just try to write the code without use the mouse trick .... and it not work.

      bkt

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sm-a
        wrote on 3 Mar 2019, 09:36 last edited by
        #3

        Thank you @gfxx,

        I tried your method, but it still doesn't work.

        I have the Stack template in use and I have added a "QT Quick UI file" with the name "TestForm". When I tried to implement this with "go to implementation" in the "TestForm" it dosen't work.

        Do you have any idea why this might be?

        Greetings,
        Sven

        G 1 Reply Last reply 3 Mar 2019, 12:35
        0
        • S sm-a
          3 Mar 2019, 09:36

          Thank you @gfxx,

          I tried your method, but it still doesn't work.

          I have the Stack template in use and I have added a "QT Quick UI file" with the name "TestForm". When I tried to implement this with "go to implementation" in the "TestForm" it dosen't work.

          Do you have any idea why this might be?

          Greetings,
          Sven

          G Offline
          G Offline
          gfxx
          wrote on 3 Mar 2019, 12:35 last edited by
          #4

          @sm-a Have you try to do sometings like these?

          in your main.qml

          
           SwipeWiew:{
                 /* some layout code */
          
                   YourFirstPageForm:{
                               /* some layout code*/
                               function yourfunction(){
                                       console.log("OK these work!!")
                             }
          yourqmlwidget.onClick: yourfunction()
                          }
                   YourSecondPageForm:{
                        }
             }
          
          /* some code for navigate*/
          
          

          These still not work? I attach some image (first, second, third step png.) So you can see my sample project ....
          0_1551616456074_firstStep.png

          0_1551616467780_SecondStep.png

          0_1551616484601_ThirdStep.png

          regards

          bkt

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sm-a
            wrote on 3 Mar 2019, 12:46 last edited by
            #5

            @gfxx very thank you this helps. But how can I define it to use "Test.qml" (from "TestForm.ui.qml") instead of "main.qml" for the definition?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gfxx
              wrote on 3 Mar 2019, 13:10 last edited by
              #6

              I try to attach my sample project ... (work to my home for techer me about qml and quick world that not know too) I am attaching my example project (which I also use to learn at home qml and quick that I do not know at all well ..). This for me works very well for what you ask ... I have problems understanding how to use tableView and qmlregistertype .... but it's another story.

              These because my english is poor so with the code explain me better.

              I not have the required perission .... so i use git these is my folder project

              Attention: in disegn mode, navigator panel control the circle with arrow state ... if not red ... the action is not performed

              I hope these help

              regards

              bkt

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shaan7
                wrote on 3 Mar 2019, 17:03 last edited by
                #7

                Hi,

                I followed the same steps as you and it works for me. My project files are like this-

                /tmp/test$ tree
                .
                ├── main.cpp
                ├── main.qml
                ├── qml.qrc
                ├── qtquickcontrols2.conf
                ├── TestForm.ui.qml
                ├── test.pro
                ├── test.pro.user
                └── Test.qml
                

                main.qml

                import QtQuick 2.12
                import QtQuick.Controls 2.5
                
                ApplicationWindow {
                    id: window
                    visible: true
                    width: 640
                    height: 480
                    title: qsTr("Stack")
                
                    StackView {
                        id: stackView
                        initialItem: "Test.qml"
                        anchors.fill: parent
                    }
                }
                
                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gfxx
                  wrote on 3 Mar 2019, 18:54 last edited by gfxx 3 Mar 2019, 18:58
                  #8

                  @ sm-a is not necessary the name "main" in main.qml .... you must declare it on qrc file and insert in on main.cpp. main.qml is the default name on qt designer system.

                  The default name is not necessary at all.... testuiform can be MyIceScream.ui.qml for example .... as said @shaan7

                  If you have solved your issue use "solved button"

                  regards

                  bkt

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    sm-a
                    wrote on 3 Mar 2019, 20:05 last edited by
                    #9

                    Many thanks to everyone who helped me (@shaan7 and @gfxx) it now works as it should.

                    G 1 Reply Last reply 4 Mar 2019, 07:00
                    1
                    • S sm-a
                      3 Mar 2019, 20:05

                      Many thanks to everyone who helped me (@shaan7 and @gfxx) it now works as it should.

                      G Offline
                      G Offline
                      gfxx
                      wrote on 4 Mar 2019, 07:00 last edited by
                      #10

                      @sm-a with pleasure ...

                      bkt

                      1 Reply Last reply
                      0

                      2/10

                      3 Mar 2019, 05:35

                      8 unread
                      • Login

                      • Login or register to search.
                      2 out of 10
                      • First post
                        2/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved