-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.cpp
32 lines (24 loc) · 967 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QSurfaceFormat>
#include "appglobal.h"
#include "quickosgviewer.h"
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
QGuiApplication app(argc, argv);
// 注册QML模块
qmlRegisterType<AppGlobal>("CppBackend", 1, 0, "AppGlobal");
qmlRegisterType<QuickOSGViewer>("QuickOSG", 1, 0, "QuickOSGViewer");
auto engine = new QQmlApplicationEngine();
engine->addImportPath(QLatin1Literal("qrc:/"));
// 构造app全局变量,将engine传入该全局变量构造函数
auto appGlobal = new AppGlobal(engine);
engine->rootContext()->setContextProperty("$app", appGlobal);
engine->rootContext()->setContextProperty("$applicationPath", app.applicationDirPath());
engine->load(QUrl(QStringLiteral("qrc:/main.qml")));
auto result = app.exec();
delete engine;
return result;
}