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. Invalid alias reference. Unable to find id

Invalid alias reference. Unable to find id

Scheduled Pinned Locked Moved Solved QML and Qt Quick
settingsaliaspropertyqmlqt quick
9 Posts 3 Posters 9.3k 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on 26 Jul 2017, 12:19 last edited by
    #1

    Hi,

    I always get this error message qrc:/Page1.qml:8 Invalid alias reference. Unable to find id "textField1" whenever I run my app

    What's wrong with my code?

    NOTE: Please forgive me for silly question because I'm still a newbie in QML

    Page1Form.ui.qml

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.3
    
    Item {
        property alias textField1: textField1
        property alias button1: button1
    
        RowLayout {
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.topMargin: 20
            anchors.top: parent.top
    
            TextField {
                id: textField1
                placeholderText: qsTr("Text Field")
            }
    
            Button {
                id: button1
                text: qsTr("Press Me")
            }
        }
    }
    

    Page1.qml

    import QtQuick 2.7
    import Qt.labs.settings 1.0
    
    Page1Form {
    
        Settings {
            id: settings
            property alias settings_host: textField1.text
        }
    
        button1.onClicked: {
            console.log("Button Pressed. Entered text: " + textField1.text);
        }
    }
    

    main.qml

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.3
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        SwipeView {
            id: swipeView
            anchors.fill: parent
            currentIndex: tabBar.currentIndex
    
            Page1 {
            }
    
            Page {
                Label {
                    text: qsTr("Second page")
                    anchors.centerIn: parent
                }
            }
        }
    
        footer: TabBar {
            id: tabBar
            currentIndex: swipeView.currentIndex
            TabButton {
                text: qsTr("First")
            }
            TabButton {
                text: qsTr("Second")
            }
        }
    }
    
    Y 1 Reply Last reply 26 Jul 2017, 13:00
    0
    • M mbnoimi
      26 Jul 2017, 12:19

      Hi,

      I always get this error message qrc:/Page1.qml:8 Invalid alias reference. Unable to find id "textField1" whenever I run my app

      What's wrong with my code?

      NOTE: Please forgive me for silly question because I'm still a newbie in QML

      Page1Form.ui.qml

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.3
      
      Item {
          property alias textField1: textField1
          property alias button1: button1
      
          RowLayout {
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.topMargin: 20
              anchors.top: parent.top
      
              TextField {
                  id: textField1
                  placeholderText: qsTr("Text Field")
              }
      
              Button {
                  id: button1
                  text: qsTr("Press Me")
              }
          }
      }
      

      Page1.qml

      import QtQuick 2.7
      import Qt.labs.settings 1.0
      
      Page1Form {
      
          Settings {
              id: settings
              property alias settings_host: textField1.text
          }
      
          button1.onClicked: {
              console.log("Button Pressed. Entered text: " + textField1.text);
          }
      }
      

      main.qml

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.3
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          SwipeView {
              id: swipeView
              anchors.fill: parent
              currentIndex: tabBar.currentIndex
      
              Page1 {
              }
      
              Page {
                  Label {
                      text: qsTr("Second page")
                      anchors.centerIn: parent
                  }
              }
          }
      
          footer: TabBar {
              id: tabBar
              currentIndex: swipeView.currentIndex
              TabButton {
                  text: qsTr("First")
              }
              TabButton {
                  text: qsTr("Second")
              }
          }
      }
      
      Y Offline
      Y Offline
      Yashpal
      wrote on 26 Jul 2017, 13:00 last edited by
      #2

      @mbnoimi Have a look at property alias from http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html

      It says, 'aliasing an aliasing property will result in an error'.

      M 1 Reply Last reply 26 Jul 2017, 17:38
      1
      • Y Yashpal
        26 Jul 2017, 13:00

        @mbnoimi Have a look at property alias from http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html

        It says, 'aliasing an aliasing property will result in an error'.

        M Offline
        M Offline
        mbnoimi
        wrote on 26 Jul 2017, 17:38 last edited by mbnoimi
        #3

        @Yashpal Thanks

        But when I move Settings { property alias settings_host: textField1.text } from Page1.qml to Page1Form.ui.qml it works fine without any problem!

        NOTE: Basically I asked this question because I want to define Settings in Page1.qml instead of Page1Form.ui.qml

        Page1.qml

        import QtQuick 2.7
        
        Page1Form {
        
            button1.onClicked: {
                console.log("Button Pressed. Entered text: " + textField1.text);
            }
        }
        

        Page1Form.ui.qml

        import QtQuick 2.7
        import QtQuick.Controls 2.0
        import QtQuick.Layouts 1.3
        import Qt.labs.settings 1.0
        
        Item {
            property alias textField1: textField1
            property alias button1: button1
        
            Settings { property alias settings_host: textField1.text }
        
        
            RowLayout {
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.topMargin: 20
                anchors.top: parent.top
        
                TextField {
                    id: textField1
                    placeholderText: qsTr("Text Field")
                }
        
                Button {
                    id: button1
                    text: qsTr("Press Me")
                }
            }
        }
        
        Y 2 Replies Last reply 27 Jul 2017, 03:35
        0
        • M mbnoimi
          26 Jul 2017, 17:38

          @Yashpal Thanks

          But when I move Settings { property alias settings_host: textField1.text } from Page1.qml to Page1Form.ui.qml it works fine without any problem!

          NOTE: Basically I asked this question because I want to define Settings in Page1.qml instead of Page1Form.ui.qml

          Page1.qml

          import QtQuick 2.7
          
          Page1Form {
          
              button1.onClicked: {
                  console.log("Button Pressed. Entered text: " + textField1.text);
              }
          }
          

          Page1Form.ui.qml

          import QtQuick 2.7
          import QtQuick.Controls 2.0
          import QtQuick.Layouts 1.3
          import Qt.labs.settings 1.0
          
          Item {
              property alias textField1: textField1
              property alias button1: button1
          
              Settings { property alias settings_host: textField1.text }
          
          
              RowLayout {
                  anchors.horizontalCenter: parent.horizontalCenter
                  anchors.topMargin: 20
                  anchors.top: parent.top
          
                  TextField {
                      id: textField1
                      placeholderText: qsTr("Text Field")
                  }
          
                  Button {
                      id: button1
                      text: qsTr("Press Me")
                  }
              }
          }
          
          Y Offline
          Y Offline
          Yashpal
          wrote on 27 Jul 2017, 03:35 last edited by
          #4

          @mbnoimi said in Invalid alias reference. Unable to find id:

          But when I move Settings { property alias settings_host: textField1.text } from Page1.qml to Page1Form.ui.qml it works fine without any problem!

          i think it's considering id 'textField1' over alias 'textField1', try to give different alias name and look how it works.

          M 1 Reply Last reply 27 Jul 2017, 09:04
          1
          • M mbnoimi
            26 Jul 2017, 17:38

            @Yashpal Thanks

            But when I move Settings { property alias settings_host: textField1.text } from Page1.qml to Page1Form.ui.qml it works fine without any problem!

            NOTE: Basically I asked this question because I want to define Settings in Page1.qml instead of Page1Form.ui.qml

            Page1.qml

            import QtQuick 2.7
            
            Page1Form {
            
                button1.onClicked: {
                    console.log("Button Pressed. Entered text: " + textField1.text);
                }
            }
            

            Page1Form.ui.qml

            import QtQuick 2.7
            import QtQuick.Controls 2.0
            import QtQuick.Layouts 1.3
            import Qt.labs.settings 1.0
            
            Item {
                property alias textField1: textField1
                property alias button1: button1
            
                Settings { property alias settings_host: textField1.text }
            
            
                RowLayout {
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.topMargin: 20
                    anchors.top: parent.top
            
                    TextField {
                        id: textField1
                        placeholderText: qsTr("Text Field")
                    }
            
                    Button {
                        id: button1
                        text: qsTr("Press Me")
                    }
                }
            }
            
            Y Offline
            Y Offline
            Yashpal
            wrote on 27 Jul 2017, 03:37 last edited by
            #5

            @mbnoimi said in Invalid alias reference. Unable to find id:

            NOTE: Basically I asked this question because I want to define Settings in Page1.qml instead of Page1Form.ui.qml

            Yes, you can do it. Make sure you don't use aliasing an aliasing property.

            1 Reply Last reply
            1
            • Y Yashpal
              27 Jul 2017, 03:35

              @mbnoimi said in Invalid alias reference. Unable to find id:

              But when I move Settings { property alias settings_host: textField1.text } from Page1.qml to Page1Form.ui.qml it works fine without any problem!

              i think it's considering id 'textField1' over alias 'textField1', try to give different alias name and look how it works.

              M Offline
              M Offline
              mbnoimi
              wrote on 27 Jul 2017, 09:04 last edited by mbnoimi
              #6

              @Yashpal

              try to give different alias name and look how it works.

              I did as you suggested but nothing changed (see below plz)!

              Make sure you don't use aliasing an aliasing property.

              I can't use Settings without creating alias from alias which is a valid thing inside Page1Form.ui.qml but it's not inside Page1.qml!

              Page1Form.ui.qml

              import QtQuick 2.7
              import QtQuick.Controls 2.0
              import QtQuick.Layouts 1.3
              
              Item {
                  property alias button1: button1
                  property alias textFieldAlias: textFieldName
              
                  RowLayout {
                      anchors.horizontalCenter: parent.horizontalCenter
                      anchors.topMargin: 20
                      anchors.top: parent.top
              
                      TextField {
                          id: textFieldName
                          placeholderText: qsTr("Text Field")
                      }
              
                      Button {
                          id: button1
                          text: qsTr("Press Me")
                      }
                  }
              }
              

              Page1.qml

              import QtQuick 2.7
              import Qt.labs.settings 1.0
              
              Page1Form {
              
                  Settings { property alias settings_host: textFieldName.text}
              
                  button1.onClicked: {
                      console.log("Button Pressed. Entered text: " + textFieldAlias.text);
                  }
              }
              

              Log

              QML debugging is enabled. Only use this in a safe environment.
              QQmlApplicationEngine failed to load component
              qrc:/main.qml:16 Type Page1 unavailable
              qrc:/Page1.qml:6 Invalid alias reference. Unable to find id "textFieldName"
              
              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbnoimi
                wrote on 30 Jul 2017, 08:05 last edited by mbnoimi
                #7

                Guys I still stuck with this problem since I posted it here :(

                I'm not sure but it seems related to Settings type.

                Can any one assure to me what if this issue a kind of bugs before report it as a bug?

                E 1 Reply Last reply 30 Jul 2017, 18:57
                0
                • M mbnoimi
                  30 Jul 2017, 08:05

                  Guys I still stuck with this problem since I posted it here :(

                  I'm not sure but it seems related to Settings type.

                  Can any one assure to me what if this issue a kind of bugs before report it as a bug?

                  E Offline
                  E Offline
                  Eeli K
                  wrote on 30 Jul 2017, 18:57 last edited by
                  #8

                  @mbnoimi
                  Page1Form.ui.qml:

                  Item {
                      property alias text: textFieldName.text
                  

                  Page1.qml:

                  Page1Form {
                      id: page1
                      Settings { property alias settings_host: page1.text}
                  
                  M 1 Reply Last reply 31 Jul 2017, 01:01
                  2
                  • E Eeli K
                    30 Jul 2017, 18:57

                    @mbnoimi
                    Page1Form.ui.qml:

                    Item {
                        property alias text: textFieldName.text
                    

                    Page1.qml:

                    Page1Form {
                        id: page1
                        Settings { property alias settings_host: page1.text}
                    
                    M Offline
                    M Offline
                    mbnoimi
                    wrote on 31 Jul 2017, 01:01 last edited by
                    #9

                    That's it @Eeli-K
                    Thanks a lot

                    1 Reply Last reply
                    0

                    7/9

                    30 Jul 2017, 08:05

                    • Login

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