Functions are not supported in a Qt Quick UI form
-
Hi:
I have a simple Qt Quick application, slightly modified from the template generated by Creator 3.6 to integrate C++ access via a singleton object.
I invoke C++ from QML to set the text of a button as follows:
Button {
id: button1
text: data_provider.get("button_text")
}This syntax gets underlined red in Creator, and I get the following error message when trying to open the qml file with design:
"Cannot open this QML document because of an error in the QML file:
Functions are not supported in a Qt Quick UI form. (M222)"Meanwhile, my application seems to run properly (i.e. the C++ function call works just fine and I can properly set the text of the button at run time). The error is very annoying as I basically cannot use Creator to work in the Design window.
What is this due to? And how to fix it?
I also updated to Creator 4.1 and it does the same as 3.6.
Regards,
JS -
Qt Quick UI Form is supposed to be a QML file with only visible element. No business logic should be present.
When you create a Qt Quick UI Form by Qt Creator. It will create two files.
- YourItemForm.ui.qml
- YourItem.qml <--- You should write the logic here.
Example:
YourItem.qml
YourItemForm { button1 { text: data_provider.get("button_text") } }
YourItemForm.ui.qml
Item { property alias button1 : button1 Button { id: button1 } }
p.s You don't need to setup the alias by your self. You may use GUI to do so.
http://doc.qt.io/qtcreator/images/qmldesigner-export-item.png
-
@benlau
Hi,
I'm using Qt 5.15 and can't have your example working. I'm trying to use the onClicked signal handler of a buttonI have SomeForm.ui.qml:
Item { property alias refresh: refreshBtn Button { id: refreshBtn // size, color, ... } }
and in Some.qml:
SomeForm { refresh.onClicked: console.log("foo") }
NOTE: this does not work either:
in Some.qml:SomeForm { refresh { onClicked: console.log("foo") } }
What am I doing wrong ?