Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Dialog before main window (i.e. a wizard)



  • Hi,

    I'm looking for the best solution to display a wizard window before a main application window. So far, this is my solution:

    // main.cpp
    auto a = new QApplication(argc, argv);
    // (....)
    auto e = new QQmlApplicationEngine;
    e->rootContext()->setContextProperty(QStringLiteral("GLOB"), GLOB); // some global object for entire QML code
    e->rootContext()->setContextProperty(QStringLiteral("otherGlobal"), &otherGlobal);
    if (GLOB->isFirstRun) {
      e->load(QUrl(QStringLiteral("qrc:/Wizard.qml")));
      a->exec();
      delete e;
      e = new QQmlApplicationEngine;
      e->rootContext()->setContextProperty(QStringLiteral("GLOB"), GLOB);
      e->rootContext()->setContextProperty(QStringLiteral("otherGlobal"), &otherGlobal);;
      GLOB->isFirstRun = false;
     }
     e->load(QUrl(QStringLiteral("qrc:/MainWindow.qml")));
    a->exec();
    (....)
    

    This way I'm calling QApplication::exec() twice, but it seems to not be a problem.
    But there is also a need to delete first instance of QQmlApplicationEngine - otherwise the wizard instance is not destroyed, it disappears only.
    So when the engine instance is created again, I have to again load e->rootContext()->setContextProperty() with those shared objects.

    It works fine, but maybe there is any better way to invoke the wizard before main app window.


Log in to reply