[Solved] ApplicationWindow in qml gives error
-
I have created a Qt Quick Application and in qml file i give the below code:
@import QtQuick 2.2
import QtQuick.Controls 1.1ApplicationWindow
{
id: rootwidth: 100 height: 100 color: "red"
}
@This gives me the below message and the screen will not display anything :
_QQuickView only supports loading of root objects that derive from QQuickItem.
If your example is using QML 2, (such as qmlscene) and the .qml file you
loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur.To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the
QDeclarativeView class in the Qt Quick 1 module._I have seen the same code used in many tutorials without any issues Your text to link here...be":http://www.youtube.com/watch?v=_6_F6Kpjd-Q
-
you need to use QQmlApplicationEngine. Below is a main.cpp file that should work for you.
@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl("qml/convQML/main.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
window->show();
return app.exec();
}
@