Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI"
-
Hello,
I have a repeater dynamically populated with images where after clicking on the image, I need to call a function with the element index as an argument.
This is the code:Repeater { model: 0 Image { source: "qrc:/images/image.svg" MouseArea { anchors.fill: parent Connections { onClicked: { myFunction(index) }}}}}
Now I got the warning
QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
so I changed it to:
... Connections { function onClicked() { myFunction(index) }
But now it gives me this:
Functions are not supported in a Qt Quick UI form (M222)
What is the right solution when converting such kind of code into the new syntax?
Thanks and have a nice day! -
hi
@Hitokage said in Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI":
Functions are not supported in a Qt Quick UI form (M222)
You can't declare/call functions in the ui file( <fileName>.ui.qml ).
Put your code in a new qml Component (.qml file) and it will work
https://doc.qt.io/qtcreator/creator-quick-ui-forms.html
note you can embed qml components (with functions) in your ui formsIf you want to use ui files, then your need to separate the logic and the view
// ViewForm.ui.qml. No logic in here, juste the view import QtQuick 2.4 Rectangle{ //... border.width:1 Repeater {anchors.fill:parent} }
// ViewForm.qml. Logic goes here import QtQuick 2.4 ViewForm { delegate: Image{ MouseArea{} } }
// use ViewForm somewhere in your app ViewForm{}
-
@Hitokage said in Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI":
so you mean like using the ViewForm item in the Repeater instead of the Image?
No that wouldn't make sense at all, i just accidentally used ListView instead of Repeater, i will correct it now