ApplicationWindow as root object result in error
Hello friends,
I have expose one c++ classes to qml in a main.cpp file like this:
Code:
int main(int argc, char** argv)
{
QGuiApplication app(argc, argv);
qmlRegisterType<MyTestClass>("Test", 1, 0, "Test");
QQuickView view;
view.resize(800, 480);
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.
setSource(QUrl("qrc:///main.qml"));
view.show();
return app.exec();
}
But my root object in qml is a ApplicationWindow object. So I get a
Quote:
QQuickView only supports loading of root objects that derive from QQuickItem.
So when I avoid the main.cpp I have to run the qml file with qmlscene. But I want to have an exe file. How can I use an main.cpp in combinatiion with a ApplicationWindow root object in a qml file?
Yours,
Re: ApplicationWindow as root object result in error
The error message is correct. ApplicationWindow is a QQuickWindow and not a QQuickItem. QQuickView is also a window which causes the problem. (you are creating a window in C++ that essentially is supposed to create another window declared in Qt Quick. If this is targetting Qt 5.1 there is a new QQmlApplicationEngine you can use for exactly this purpose. Alternatively is that you create a QQmlEngine yourself instead of a QQuickView to launch your qml file.
http://doc-snapshot.qt-project.org/q...ionengine.html
Re: ApplicationWindow as root object result in error
hello,
i had the same problem with Quickview but when i switched into QQmlApplicationEngine and then run the application nothing happens , i mean no gui is loaded only the application process is launched and no error is availble , any ideas plz ?
main.cpp :
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engin(QUrl("qrc:/main.qml"));
return app.exec();
}
Re: ApplicationWindow as root object result in error
You are correct that QQmlApplicationEngine should be used. Just note that it doesn't show() the window, so you should explicitly set the visibility on the ApplicationWindow to true;