Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Properly set my main.cpp
Forum Updated to NodeBB v4.3 + New Features

Properly set my main.cpp

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 507 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The solution is provided in the error message: use QQmlApplicationEngine in place of QQuickView.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved