I have the following issue.
I'm using QML for my application frontend.
For one of my componentes I use a ListView that uses a custom delegate that contains it's own index (and some other data) in a a variable called vmIndex. Here is the declaration of the list view:
ListView {
id: studySelectListView
anchors.fill: parent
model: studySelectList
delegate: VMStudyEntry {
width: studySelectBackground.width
height: studySelectBackground.height/4
onItemSelected: {
selectionChanged(vmIndex,true); // LINE WITH WARNING
}
}
}
Now, when the item is selected I need to call a function called selectionChange and send vmIndex as a parameter to that function.
The VMStudyEntry is this:
Item {
id: vmStudyEntry
signal itemSelected(int vmIndex);
MouseArea {
anchors.fill: parent
onClicked: {
vmStudyEntry.itemSelected(vmIndex);
}
}
Rectangle {
id: dateRect
color: vmIsSelected? "#3096ef" : "#ffffff"
border.color: vmIsSelected? "#144673" : "#3096ef"
radius: mainWindow.width*0.005
border.width: mainWindow.width*0.0005
anchors.fill: parent
Text {
font.family: viewHome.gothamR.name
font.pixelSize: 12*viewHome.vmScale
text: vmStudyName
color: vmIsSelected? "#ffffff" : "#000000"
anchors.centerIn: parent
}
}
}
This all worked perfectly on Qt 5.13.2. But I now moved to Qt 6.1.2. The code actually still works, as far as I can see but I'm getting this warning:
Parameter "vmIndex" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
The line that has this warning is identifed above. Can anyone tell me how I can redefine this in order to make this warning go away?
CodePudding user response:
Take a look here, you need the following syntax in Qt6:
onItemSelected: function(vmIndex) { selectionChanged(vmIndex,true); }
Or a more lambda-like options if you fancy:
onItemSelected: vmIndex => selectionChanged(vmIndex, true)