Invalid alias reference. Unable to find id



  • 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")
            }
        }
    }
    


  • @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'.



  • @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")
            }
        }
    }
    


  • @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.



  • @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.



  • @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"
    


  • 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?



  • @mbnoimi
    Page1Form.ui.qml:

    Item {
        property alias text: textFieldName.text
    

    Page1.qml:

    Page1Form {
        id: page1
        Settings { property alias settings_host: page1.text}
    


  • That's it @Eeli-K
    Thanks a lot



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.