Invalid alias reference. Unable to find id
Hi,
I always get this error message whenever I run my app:
Code:
qrc:/Page1.qml:8 Invalid alias reference. Unable to find id "textField1"
What's wrong with my code?
NOTE: Please forgive me for silly question because I'm still a newbie in QML
Page1Form.ui.qml
Code:
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
Code:
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
Code:
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")
}
}
}
Re: Invalid alias reference. Unable to find id
Please try if it works if you specify the attribute like this
Code:
import QtQuick 2.7
import Qt.labs.settings 1.0
Page1Form {
id: myPage1Form
Settings {
id: settings
property alias settings_host: myPage1Form.textField1.text
}
button1.onClicked: {
console.log("Button Pressed. Entered text: " + textField1.text);
}
}
Re: Invalid alias reference. Unable to find id
Thanks for delayed reply ;)
@Eeli-K gave me a pretty solution:
https://forum.qt.io/post/407571