PDA

View Full Version : Invalid alias reference. Unable to find id



M. Bashir
26th July 2017, 14:39
Hi,

I always get this error message whenever I run my app:

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

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

sedi
22nd August 2017, 17:44
Please try if it works if you specify the attribute like this


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);
}
}

M. Bashir
22nd August 2017, 18:12
Thanks for delayed reply ;)

@Eeli-K (https://forum.qt.io/uid/29871) gave me a pretty solution:
https://forum.qt.io/post/407571