-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
42 lines (30 loc) · 1.1 KB
/
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
33
34
35
36
37
38
39
40
41
#include <QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QQmlContext>
#include <View.h>
#include <QApplication>
//Entry point of the application
int main(int argc, char *argv[])
{
//Application attributes
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//The application class
QApplication app(argc, argv);
//The QML Engine
QQmlApplicationEngine engine;
//Add to the root context
View view;
engine.rootContext()->setContextProperty("view_", &view);
//The URL of the QML file, notice this is a compiled resource
const QUrl url(QStringLiteral("qrc:/window.qml"));
//Connecting a signal and slot - making sure the object and url match
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
//The engine loading the QML file
engine.load(url);
//The application entering an event loop that keeps the application open
return app.exec();
}