main.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. const QUrl url(QStringLiteral("qrc:/dev.qml"));
  17. if(appCtrl.Create(_APP_ID, _APP_NAME, _UPDATE_TIMER_INT, _UPDATE_TIMER_INT_HEAVY_LOAD))
  18. {
  19. appCtrl.SubscribeStateEvents(GFA_APPCTRL_APPID_ALL_GFA);
  20. appCtrl.SetState(GIAS_Initializing);
  21. QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  22. &app, [url, &appCtrl](QObject *obj, const QUrl &objUrl) {
  23. if (!obj && url == objUrl)
  24. {
  25. appCtrl.SetState(GIAS_Terminating);
  26. appCtrl.Release();
  27. QCoreApplication::exit(-1);
  28. }
  29. }, Qt::QueuedConnection);
  30. appCtrl.RegisterQmlTypes(engine, 1, 0);
  31. engine.load(url);
  32. appCtrl.SetState(GIAS_Running);
  33. nRet = app.exec();
  34. appCtrl.SetState(GIAS_Terminating);
  35. }
  36. return nRet;
  37. }