Important: Please read the Qt Code of Conduct -

Creating a start dialog to set options which functionalities to load - second QQmlApplicationEngine?

  • Hello,

    I have a program which can access hardware or can be used as a file reader without hardware.

    I would like to show the user a QML dialog at software start to select whether the software shall run in hardware access mode or file reader mode. And then afterwards I would like to create instances of the necessary classes and set the right context properties in my main.cpp.

    How can I achieve this?
    I thought about creating two QQmlApplication engines.
    The first one asks the user, sets a variable which mode shall be used and is then closed.
    Then the necessary classes would be instantiated, registered and the main QQmlApplicationEngine would load.

    Is there another good way?
    If I would try it like described, my question is, how can I make my Code in my main.cpp wait until the first engine is closed (engine.load() is not blocking)?

    Thank you very much :-)

  • @robro

    Would something like the following work:

    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        QQmlApplicationEngine* engine;
        engine = new QQmlApplicationEngine();
        //setup engine for app1
        //Setup C++ to get values back from engine
        if (engine->rootObjects().isEmpty())
            return -1;
        int a = app.exec();
        qDebug() << "Ended App 1 with result: " << a;
        engine = new QQmlApplicationEngine();
        //Setup engine for app2
        if (engine->rootObjects().isEmpty())
            return -1;
        int b = app.exec();
        qDebug() << "Ended App 2 with result: " << b;
        return b;

  • Thank you very much!

Log in to reply