1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include <QGuiApplication>
- #include <QQmlApplicationEngine>
- #include "qappctrl.h"
- #define _APP_ID GFA_APPCTRL_CTRLMSG_USER_01
- #define _APP_NAME "qmlApp"
- #define _TIMER_INT 50
- int main(int argc, char *argv[])
- {
- int nRet = -1;
- QGfaAppCtrl appCtrl;
- QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QGuiApplication app(argc, argv);
- QQmlApplicationEngine engine;
- const QUrl url(QStringLiteral("qrc:/main.qml"));
- if(appCtrl.Create(_APP_ID, _APP_NAME, _TIMER_INT))
- {
- appCtrl.SubscribeStateEvents(GFA_APPCTRL_APPID_ALL_GFA);
- appCtrl.SetState(GIAS_Initializing);
- QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
- &app, [url, &appCtrl](QObject *obj, const QUrl &objUrl) {
- if (!obj && url == objUrl)
- {
- appCtrl.SetState(GIAS_Terminating);
- appCtrl.Release();
- QCoreApplication::exit(-1);
- }
- }, Qt::QueuedConnection);
- appCtrl.RegisterQmlTypes(engine, 1, 0);
- engine.load(url);
- appCtrl.SetState(GIAS_Running);
- nRet = app.exec();
- appCtrl.SetState(GIAS_Terminating);
- }
- return nRet;
- }
|