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 Update on Tuesday, May 27th 2025

Properly set my main.cpp

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 489 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 17 Oct 2018, 14:11 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Oct 2018, 17:15 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 18 Oct 2018, 06:02 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        1/3

        17 Oct 2018, 14:11

        • Login

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