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. Proper way for C++ code at startup signalize something to QML

Proper way for C++ code at startup signalize something to QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 282 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.
  • T Offline
    T Offline
    TiagoSD
    wrote on last edited by
    #1

    Hello, I have migrated from old style QT into QtQuick recently and I am liking a lot, but I am still having some difficulties (for that reason there will be more than one Question on the same context posted by me)

    I have an application that in startup time I check if local credentials are still valid, if they are the c++ engine behind scenes operate normally. IF they are not valid, I need to make the interface (QML) go to the login screen. The main code is as follows.

    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        auto *backend_engine = new aquila_backend(&app);
    
        engine.rootContext()->setContextProperty("aquila", backend_engine);
    
        const QUrl url(u"qrc:/aquila_companion/Main.qml"_qs);
        QObject::connect(&engine, &QQmlApplicationEngine::quit, &QGuiApplication::quit);
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
            &app, []() { QCoreApplication::exit(-1); },
            Qt::QueuedConnection);
        engine.addImportPath(QCoreApplication::applicationDirPath() + "/backend");
        engine.addImportPath(":/");
        engine.load(url);
    
        QObject* obj = engine.rootObjects().first();
        QObject::connect(backend_engine, SIGNAL(append_log(QVariant)), obj, SLOT(append_log(QVariant)));
        QObject::connect(backend_engine, SIGNAL(go_to_login_screen(QVariant)), obj, SLOT(go_to_login_screen(QVariant)));
    
        backend_engine->data_folder = defaultFolderPath();
        backend_engine->load_credentials();
        //PROBLEM HAPPENS HERE
        return app.exec();
    }
    
    

    The checkup is made at load_credentials. The problem is, the app is not executing at that moment so I cannot send a signal to the app (and the return of that credential online validation can vary). What is the correct idiomatic way to solve this issue? I do not want to freeze the whole application without an interface just waiting for the validation, but I see that I cannot risk to emit a signal to the App if the validation returns before the interface is loaded.

    JoeCFDJ 1 Reply Last reply
    0
    • T TiagoSD

      Hello, I have migrated from old style QT into QtQuick recently and I am liking a lot, but I am still having some difficulties (for that reason there will be more than one Question on the same context posted by me)

      I have an application that in startup time I check if local credentials are still valid, if they are the c++ engine behind scenes operate normally. IF they are not valid, I need to make the interface (QML) go to the login screen. The main code is as follows.

      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          auto *backend_engine = new aquila_backend(&app);
      
          engine.rootContext()->setContextProperty("aquila", backend_engine);
      
          const QUrl url(u"qrc:/aquila_companion/Main.qml"_qs);
          QObject::connect(&engine, &QQmlApplicationEngine::quit, &QGuiApplication::quit);
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
              &app, []() { QCoreApplication::exit(-1); },
              Qt::QueuedConnection);
          engine.addImportPath(QCoreApplication::applicationDirPath() + "/backend");
          engine.addImportPath(":/");
          engine.load(url);
      
          QObject* obj = engine.rootObjects().first();
          QObject::connect(backend_engine, SIGNAL(append_log(QVariant)), obj, SLOT(append_log(QVariant)));
          QObject::connect(backend_engine, SIGNAL(go_to_login_screen(QVariant)), obj, SLOT(go_to_login_screen(QVariant)));
      
          backend_engine->data_folder = defaultFolderPath();
          backend_engine->load_credentials();
          //PROBLEM HAPPENS HERE
          return app.exec();
      }
      
      

      The checkup is made at load_credentials. The problem is, the app is not executing at that moment so I cannot send a signal to the app (and the return of that credential online validation can vary). What is the correct idiomatic way to solve this issue? I do not want to freeze the whole application without an interface just waiting for the validation, but I see that I cannot risk to emit a signal to the App if the validation returns before the interface is loaded.

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @TiagoSD start a splash screen with some fancy animation and then do load_credentials. If valid, switch to login screen?

      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