main.cpp 1.2 KB

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