main.cpp 1.1 KB

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