Beginner problem - ReferenceError: text is not defined
Hello,
I'm new in Qt-Quick and QML.
I'm learning how to use it with C++.
So I start with this tutorial and I use Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) :
https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
with the only difference that I use pageform.ui.qml files.
so on a pageforme I have a text field:
Code:
TextField {
id: textfield
text: "Text"
placeholderText: qsTr("User name")
anchors.centerIn: parent
}
and in main.qml:
Code:
Page3Form {
textfield
{
text: backend.userName
onTextChanged: backend.userName = text
}
}
if I use it like that onTextChaned doesn't works and I've got an error in the debugger console:
Code:
qrc:/main.qml:51: ReferenceError: text is not defined
But if I do this in main.qml :
Code:
Page3Form {
textfield
{
text: backend.userName
onTextChanged: backend.userName = textfield.text
}
}
It works but I have this message:
Code:
qrc:/Page3Form.ui.qml:25:5: QML TextField: Binding loop detected for property "text"
is someone has a clue?
Regards.
Re: Beginner problem - ReferenceError: text is not defined
Do you need every text change to be forwarded to the C++ object?
Or could you do with just onEditingFinished?
Cheers,
_
Re: Beginner problem - ReferenceError: text is not defined
You're right, onEditingFinished is better for what I want to do and the warning is gone.
Thank you
PS: I had a look on the documentation and i found onEditingFinsihed but I didn't find onTextChanged, is it normal?
https://doc.qt.io/qt-5/qml-qtquick-c...textfield.html
https://doc.qt.io/qt-5/qml-qtquick-c...textfield.html
Re: Beginner problem - ReferenceError: text is not defined
Quote:
Originally Posted by
zodd
PS: I had a look on the documentation and i found onEditingFinsihed but I didn't find onTextChanged, is it normal?
Yes, because textChanged() is not an explicit signal.
All properties have associated signals for indicating that their value has changed.
The naming convention for these is "property name" + "Changed"
So, since the TextField has a "text" property, it also has a "textChanged" signal.
These property change notification signals are not documented to avoid bloating the documentation, i.e. only additional, element specific signals are listed.
Cheers,
_
P.S.: as a general rule of thumb also check that your property setter function emits its associated signal only when the property's value really changed.
This is to avoid unnecessary binding reevaluation
Re: Beginner problem - ReferenceError: text is not defined
OK, I understand.
Thank your for the clarification and for your advice ;)