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. Custom Component
Qt 6.11 is out! See what's new in the release blog

Custom Component

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 620 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.
  • S Offline
    S Offline
    sush123
    wrote on last edited by
    #1
    This post is deleted!
    ODБOïO 1 Reply Last reply
    0
    • S Offline
      S Offline
      sush123
      wrote on last edited by
      #4
      This post is deleted!
      1 Reply Last reply
      1
      • S sush123

        This post is deleted!

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

        @sush123 hi

        I did a quick test, and i don't have val1 is not defined error.
        Its hard give you an answer because we don't know how InputRow is defined.
        I did a very simple InputRow Component to test your code

        //InputRow.qml

        import QtQuick 2.12
        import QtQuick.Layouts 1.12
        RowLayout{
            property var component
        }
        
        

        //your code

        
        
        Window {
            visible: true
            width: 300
            height: 300
        
            InputRow{
        
                component:  Column{
                    spacing: 10
                    Row{
        
                        spacing: 50
        
                        Text{
                            text: "Val1"
                            font.pointSize: 10
                        }
                        TextInput {
                            id:val1
                            width: 5
                            text: "777"
                            font.pointSize: 10
                        }
        
                        Text{
                            text: "m"
                            font.pointSize: 10
                        }
                    }
                    Row{
                        spacing: 50
        
                        Text{
                            text: "Val2"
                            font.pointSize: 10
                        }
        
                        TextInput {
                            id:val2
                            width: 5
                            text:"888"
                            font.pointSize: 10
        
                        }
        
                        Text{
                            text: "m"
                            font.pointSize: 10
                        }
                    }
                }                    //End of Column
        
        
            }
            
            
            Button{
                text: "Send"
        
                onClicked:
                {
                    console.log("VAL1",val1.text)   //ReferenceError: val1 is not defined,
                    console.log("VAL2",val2.text)
                    console.log("SEND")
        
                }
            }
        }
        
        
        
        
        
        
        
        
        
        
        

        i get this output

        qml: VAL1 777
        qml: VAL2 888
        qml: SEND
        

        and no error

        1 Reply Last reply
        1
        • ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #3

          @sush123
          i managed to reproduce the error by defining InputRow like this :
          //InputRow.qml

          import QtQuick 2.0
          import QtQuick.Layouts 1.12
          
          RowLayout{
              property alias inputContent : content // i use this to access the loader.item
              
              property var component
              Loader{
                  id:content
                  Layout.fillHeight: true
                  Layout.fillWidth: true
                  sourceComponent:component
              }
          }
          

          and use it

          component : Component{
                      id: userInput
                      Column{...}
          }
          

          then the only way i found to access val1 is this
          userInput.inputContent.item.children[0].children[1].text
          but this is too ugly ^^

          But i have another idea, one solution that will work in any case for sure, no matter how your InputRow is defined
          simply create 2 properties, and assign them when the TextInput text changes

          InputRow{
                 id: userForm
                 property var userInput1
                 property var userInput2
          
                 component : 
                     Column{
          ...
                    TextInput {
                             id:val1
                             text: "777"
                             onTextChanged: userForm.userInput1 = text
                             Component.onCompleted : userForm.userInput1 = text 
                         }
                     }
          Button{
             onClicked : console.log(userForm.userInput1)
          }
          

          only drawback is that you create 2 additional variables

          1 Reply Last reply
          2
          • S Offline
            S Offline
            sush123
            wrote on last edited by
            #4
            This post is deleted!
            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