[Interest] MouseArea not working when using QQMLApplicationEngine with Window

Gian Maxera gmaxera at gmail.com
Thu Oct 1 10:51:24 CEST 2015


Hello,
I’m getting a strange behaviour and I didn’t find what’s wrong in my code.
I developed various app for Android and iOS using Qt and I always used the QQuickView and a simple Item as the QML root item.
In this case everything works perfectly.
This is a minimal setup that works for me fine on Android and iOS:

main.cpp:

	QQuickView viewer;
	backend->setQuickView( &viewer );
	viewer.setResizeMode( QQuickView::SizeRootObjectToView );
	viewer.setSource( backend->commonPath()+"/qml/main.qml" );
	viewer.show();

and into the main.qml:

Item {
	anchors.fill: parent

	Rectangle {
		anchors.fill: parent
		color: "steelblue"

		Text {
			anchors.centerIn: parent
			text: "Hello World !!"
		}

		MouseArea {
			anchors.fill: parent
			onClicked: {
				console.log(“CLICKED”)
			}
		}
	}

	Component.onCompleted: {
		console.log(“COMPONENT LOADED")
	}
}

Now, I would like to give a try to the QQmlApplicationEngine used with a Window as root item. It allow me to have potentially more interesting features to use into the apps.

But when I change the code in the following way:

main.cpp:

	QQmlApplicationEngine engine;
	backend->setQmlEngine( &engine );
	engine.load(QUrl(backend->commonPath()+"/qml/main.qml"));


and the main.qml:

Window {
	visible: true

	Rectangle {
		anchors.fill: parent
		color: "steelblue"

		Text {
			anchors.centerIn: parent
			text: "Hello World !!"
		}

		MouseArea {
			anchors.fill: parent
			onClicked: {
				console.log(“CLICKED”)
			}
		}
		Component.onCompleted: {
			console.log(“COMPONENT LOADED")
		}
	}

}

I don’t get any print on the console. No print for component loaded, and no print when I touch inside the MouseArea !!
Why ?? What’s happening ?

Ciao,
Gianluca.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151001/d4f62eff/attachment.html>


More information about the Interest mailing list