Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI"
-
wrote on 18 Mar 2021, 17:06 last edited by
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! -
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!wrote on 18 Mar 2021, 18:15 last edited by ODБOï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{}
-
wrote on 18 Mar 2021, 18:22 last edited by Hitokage
@LeLev Thank you!
Ah, so you mean like using the ViewForm item in the Repeater instead of the Image? -
@LeLev Thank you!
Ah, so you mean like using the ViewForm item in the Repeater instead of the Image?wrote on 18 Mar 2021, 18:38 last edited by@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
-
wrote on 18 Mar 2021, 18:47 last edited by
@LeLev Sorry, my bad. I got confused! The only thing I still don't understand is the delegate part. Does it, in other words, serve as the Repeater item? How does the delegate connect to the Repeater? What if there are multiple Repeaters?
-
@LeLev Sorry, my bad. I got confused! The only thing I still don't understand is the delegate part. Does it, in other words, serve as the Repeater item? How does the delegate connect to the Repeater? What if there are multiple Repeaters?
wrote on 18 Mar 2021, 19:46 last edited by -
wrote on 19 Mar 2021, 07:01 last edited by
@LeLev Many thanks!
3/7