I have a QML Quick Form where I have an image and an associated mouse area as follows:
// StatusBarForm.ui.qml
Image {
id: exitButton
width: 24
height: 24
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 5
source: "images/exit.png"
MouseArea {
id: exitButtonMouseArea
anchors.fill: parent
}
}
Now, according to the docs I should separate the business logic and the designer created a StatusBar.qml
form and I added:
exitButtonMouseArea.onClicked: {
Qt.quit()
}
Now the thing is I tested it with Qt 5.9 on a mac and it worked (although the Qt creator highlighted the onClicked
handler complaining that exitButtonMouseArea identifier was not valid
. I also tried exitButton.exitButtonMouseArea.onClicked:
Now I tried it with Qt 5.8
on Linux and the application does not initialize. if I remove the event handler it's fine except of course I cannot interact with the image.
So, my question is how can I provide the business logic outside of the UI file in my case.
EDIT Following @derM answer, I did the following:
// StatusBarForm.ui.qml
Image {
id: exitButton
width: 24
height: 24
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 5
source: "images/exit.png"
}
// StatusBar.qml
StatusBarForm {
property alias exitButton: exitButton
Image {
id: exitButton
MouseArea {
id: exitButtonMouseArea
anchors.fill: parent
onClicked: {
Qt.quit()
}
}
}
}
While my component initializes, I never get the onClicked
event.