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. Creating a start dialog to set options which functionalities to load - second QQmlApplicationEngine?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 507 Views
  • 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.
  • R Offline
    R Offline
    robro
    wrote on last edited by
    #1

    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 :-)

    DiracsbracketD 1 Reply Last reply
    0
    • R robro

      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 :-)

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @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
          //...
          engine->load(QUrl(QStringLiteral("qrc:/main1.qml")));
      
          if (engine->rootObjects().isEmpty())
              return -1;
      
          int a = app.exec();
          qDebug() << "Ended App 1 with result: " << a;
          delete(engine);
      
          engine = new QQmlApplicationEngine();
          //Setup engine for app2
          //...
          engine->load(QUrl(QStringLiteral("qrc:/main2.qml")));
      
          if (engine->rootObjects().isEmpty())
              return -1;
      
          int b = app.exec();
          qDebug() << "Ended App 2 with result: " << b;
      
          delete(engine);
          return b;
      }
      
      1 Reply Last reply
      1
      • R Offline
        R Offline
        robro
        wrote on last edited by
        #3

        Thank you very much!

        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