Ive created a new QML project based on Qt 5.9.3. I setup a simple ApplicationWindow with a Button as well as my own button (MyButton) and I never get the onClicked() event to fire (apparently) for either of them. My application window pops up with 2 buttons showing. Clicking on either of them shows nothing in my console output.
Im also pre-compiling my qml source files in the .pro file if that even matters. I get some Font errors on startup which I fix in the C++ to get some fonts going so I can see something, other than that there are no errors or warnings. Ive spent a couple hours just trying to get a simple mouse click event through with no luck.
Any help is appreciated.
Here's my main.qml:
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: "App Title"
color: "white"
Button {
text: "Button"
onClicked: {
console.log("clicked")
}
}
MyButton {
anchors.right: parent.right
anchors.top: parent.top
onClicked: {
console.log("my button clicked")
}
}
}
and MyButton.qml
import QtQuick 2.7
Rectangle {
id: button
width: 100
height: 50
color: "yellow"
signal clicked()
MouseArea {
id: mouseArea
anchors.fill: button
visible: false
enabled: true
onClicked: {
console.log("my button mouse clicked")
clicked()
}
}
}
UPDATE: I did a very stupid thing. in my main.cpp file which I did not include I thought I would be cleaner and move my QQmlEngine init code into its own separate method. Of course when the engine reference went out of scope it caused my issue. I didn't look there because I wrongly assumed that the qml code wouldn't work at all if something were wrong there. Sorry to get back on this so late, its been a very busy week and sorry for wasting bandwidth. Thank you for the great debugging suggestions as well for future reference!