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 accessing ui object.
Forum Updated to NodeBB v4.3 + New Features

Qml accessing ui object.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 3 Posters 2.6k 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.
  • P Offline
    P Offline
    petitDoigtPuissant
    wrote on last edited by
    #1

    Hello everyone ,
    I decided recently to learn Qml to upgrade my app design .
    (I'm new with Qt in general)

    However i have some issues with Qml and cannot find the solution to my problem , i think that i didn't understand well the logic behind accessing object in Qml.
    The task is simple i have a label and a button whenever i click the button i want the text on the label to change .
    I read the Qt documentation saw tutorials , and read a post on the forum where someone wanted to access an object but this is still not working .

    Here is a sample of my code and thanks to everyone who will help me !

    //myfile.ui
       property alias partSelectionLabel: partSelectionLabel
       property alias part1Button: part1Button
    
        Label {
            id: partSelectionLabel
         .....
    }
     Button {
                id: part1Button
    ...
    }
    
    //myfile.qml
    
       part1Button.onClicked: {
            partSelectionLabel.text = "Part 1 Selected"
    }
    
    E 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Im not in QML but in case you didn't stumble over
      https://qmlbook.github.io/

      1 Reply Last reply
      0
      • P Offline
        P Offline
        petitDoigtPuissant
        wrote on last edited by
        #3

        I saw this one and i tried to copy their code logic but still my code isn't working.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You dont get any errors clicking the button ?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            petitDoigtPuissant
            wrote on last edited by
            #5

            no nothing it is just not working my label stay the same

            mrjjM 1 Reply Last reply
            0
            • P petitDoigtPuissant

              no nothing it is just not working my label stay the same

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @petitDoigtPuissant
              Try with

              part1Button.onClicked: {
              console.log("Button Pressed: ");
              }

              Project loads and run, correct ?
              Its just that nothing happens when button is clicked ?

              Im not sure if you need a mouse area.
              https://stackoverflow.com/questions/32893811/creating-a-custom-qml-button-with-native-look-and-feel

              Anyway. give it some time , other user can tell this easy.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                petitDoigtPuissant
                wrote on last edited by
                #7

                I tried the console.log before.
                i just tried again with your code and there is nothing in the console this is so weird because it would say that it is not even entering the "function".

                yes yes the projects loads and run with no error i have my window my label and my buttons but nothing is happening.

                I will take a look, but if its a button i should not need it i think.
                Yes no worry i'm stuck with this since 4 days so one more day won't hurt.

                1 Reply Last reply
                0
                • P petitDoigtPuissant

                  Hello everyone ,
                  I decided recently to learn Qml to upgrade my app design .
                  (I'm new with Qt in general)

                  However i have some issues with Qml and cannot find the solution to my problem , i think that i didn't understand well the logic behind accessing object in Qml.
                  The task is simple i have a label and a button whenever i click the button i want the text on the label to change .
                  I read the Qt documentation saw tutorials , and read a post on the forum where someone wanted to access an object but this is still not working .

                  Here is a sample of my code and thanks to everyone who will help me !

                  //myfile.ui
                     property alias partSelectionLabel: partSelectionLabel
                     property alias part1Button: part1Button
                  
                      Label {
                          id: partSelectionLabel
                       .....
                  }
                   Button {
                              id: part1Button
                  ...
                  }
                  
                  //myfile.qml
                  
                     part1Button.onClicked: {
                          partSelectionLabel.text = "Part 1 Selected"
                  }
                  
                  E Offline
                  E Offline
                  Eeli K
                  wrote on last edited by
                  #8

                  @petitDoigtPuissant It's difficult to say if your code is well-formed because you may have cut off some of it. Please post the whole files if they aren't too large. If these were the whole files they can't work.

                  And name the files which contain your components/types beginning with an uppercase letter. Type names begin with upper case, property names with lower case.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    petitDoigtPuissant
                    wrote on last edited by
                    #9
                    //SettingPageForm.ui.qml
                    import QtQuick 2.4
                    import QtQuick.Controls 2.2
                    import QtQuick.Controls.Material 2.0
                    import QtQuick.Layouts 1.0
                    
                    PageBackground {
                        id: pageBackground
                        property alias part2Button: part2Button
                        property alias part1Button: part1Button
                        property alias partSelectionLabel: partSelectionLabel
                    
                        RowLayout {
                            y: 318
                            spacing: 20
                            anchors.left: parent.left
                            anchors.leftMargin: 333
                    
                            Button {
                                id: part1Button
                                text: qsTr("Part 1")
                                Layout.preferredHeight: 60
                                Layout.preferredWidth: 142
                                highlighted: true
                            }
                    
                            Button {
                                id: part2Button
                                text: qsTr("Part 2")
                                Layout.preferredHeight: 60
                                Layout.preferredWidth: 142
                                highlighted: true
                            }
                        }
                    
                        Text {
                            id: partSelectionLabel
                            x: 370
                            width: 252
                            height: 46
                            text: qsTr("Select a ship part")
                            fontSizeMode: Text.HorizontalFit
                            anchors.top: parent.top
                            anchors.topMargin: 150
                            font.bold: true
                            font.capitalization: Font.AllUppercase
                            horizontalAlignment: Text.AlignHCenter
                            font.pixelSize: 22
                        }
                    }
                    
                    
                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      petitDoigtPuissant
                      wrote on last edited by
                      #10
                      //SettingPage.qml
                      import QtQuick 2.4
                      
                      
                      SettingPageForm {
                      
                          part1Button.onClicked: {
                             console.log("Button pressed: ");
                             partSelectionLabel.text = "Part 1 Selected";
                          }
                      
                      
                      //    part2Button.onClicked: {
                      //        partSelectionLabel.text = "Part 2 Selected";
                      
                      //    }
                      
                      }
                      
                      
                      
                      

                      these are the files concerned . To create the signal on the button i did just like in a QtStudio video on Youtube right click on the button in the ui and go to implementation. But it seems like the button is not responding because even the console.log i put doesn't appear

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        petitDoigtPuissant
                        wrote on last edited by
                        #11

                        ok so guys sorry i just found my error .
                        It was very very stupid i wasn't on release mode but in debug .
                        I got it when i thought about why nothing was printing into the console when i was putting console.log.
                        Everything is working now !

                        anyway thank you !

                        1 Reply Last reply
                        1

                        • Login

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