main.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <QGuiApplication>
  2. #include <QQmlApplicationEngine>
  3. #include "main.h"
  4. int main(int argc, char *argv[])
  5. {
  6. int nRet = -1;
  7. QGfaAppCtrl appCtrl;
  8. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  9. QGuiApplication app(argc, argv);
  10. QQmlApplicationEngine engine;
  11. const QUrl url(QStringLiteral("qrc:/main.qml"));
  12. if(appCtrl.Create(_APP_ID, _APP_NAME, _UPDATE_TIMER_INT, _UPDATE_TIMER_INT_HEAVY_LOAD))
  13. {
  14. appCtrl.SubscribeStateEvents(_APP_SUBSCRIPTIONS);
  15. appCtrl.SetState(GIAS_Initializing);
  16. QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  17. &app, [url, &appCtrl](QObject *obj, const QUrl &objUrl) {
  18. if (!obj && url == objUrl)
  19. {
  20. appCtrl.SetState(GIAS_Terminating);
  21. appCtrl.Release();
  22. QCoreApplication::exit(-1);
  23. }
  24. }, Qt::QueuedConnection);
  25. appCtrl.RegisterQmlTypes(engine, 1, 0);
  26. engine.load(url);
  27. appCtrl.SetState(GIAS_Running);
  28. nRet = app.exec();
  29. appCtrl.SetState(GIAS_Terminating);
  30. }
  31. return nRet;
  32. }