Rectangle as a root error in QtQuick project
-
Hi guys
I'm after update to 5.3 version, I have some troubles creating QtQuick projects... With 5.2.1 version when I set a Rectangle as a root of my project, had no problem... Now, when I create a QtQuick project, QtCreator generate a main.qml as we all know, and the root object is Window.
if I change Window by Rectangle, the application doesn't show... here is the code:
This is the coge generated by qtcreator:
@import QtQuick 2.2
Window {
visible: true
width: 360
height: 360MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } } Text { text: qsTr("Hello World") anchors.centerIn: parent }
}
@This is what it doesn't work
@import QtQuick 2.2
Rectangle {
visible: true
width: 360
height: 360MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } } Text { text: qsTr("Hello World") anchors.centerIn: parent }
}
@I'm using OS X 10.9.3
regards
Freddy
-
Hi,
If you change main.qml, you also need to change main.cpp
@
// Change this...
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));// ...to this:
QQuickView view(QUrl(QStringLiteral("qrc:///main.qml")));
view.show();
@QQmlApplicationEngine takes Window. QQuickView takes Rectangle.
-
Thanks JSKH, for your reply...
and when is it better use QQmlApplicationEngine and QQuickView ??
regards
-
You're welcome :)
[quote author="freddy311082" date="1401503871"]when is it better use QQmlApplicationEngine and QQuickView ??[/quote]If you want a top-level QML window that has a menubar, statusbar and/or toolbar, then you should use QQmlApplicationEngine (with "ApplicationWindow":http://qt-project.org/doc/qt-5/qml-qtquick-controls-applicationwindow.html as your root).
If you want to embed a QML GUI inside a widget GUI, you should use QQuickView (Qt 5.0 -- Qt 5.2) or QQuickWidget (Qt 5.3 and later).
But if you don't need either of these, then it doesn't really matter which one you choose.