Properly set my main.cpp
Solved
QML and Qt Quick
-
Hello,
I do have a QML app which work fine. But at starts I have a warning message telling me this :
QQuickView does not support using windows as a root item. If you wish to create your root window from QML, consider using QQmlApplicationEngine instead.
The message is quite clear about what is wrong but I dont know how to correct it properly.
Here is my main.cpp
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); qmlRegisterType<RadialBar>("CustomControls", 1, 0, "RadialBar"); QQuickView *view = new QQuickView(); //This is causing the warning message but I don't know how to replace it and still be able to use the contextProperty KeyBoardHelper *keyboard = new KeyBoardHelper(view); qmlRegisterUncreatableType<KeyBoardHelper>("Keyboard",1,0,"KeyBoardHelper",""); view->rootContext()->setContextProperty("kb",keyboard); view->setSource(QStringLiteral("qrc:/main.qml")); return app.exec(); }
Does anybody know what kind of change I should make here and eventually give me some advice/good practice for the main.cpp
Thank you in advance
-
Hi,
The solution is provided in the error message: use QQmlApplicationEngine in place of QQuickView.