-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
61 lines (50 loc) · 2.01 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QNetworkAccessManager>
#include <QSettings>
#include "src/controller/network-data-controller.h"
#include "src/controller/owm-controller.h"
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
}
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
app.setOrganizationName("codefruit");
app.setOrganizationDomain("codefruit.de");
app.setApplicationName("QML Weather App");
QSettings* settings = new QSettings();
if (settings->value("general/systemLang").isNull()) {
QLocale l = QLocale::system();
QStringList langs = l.uiLanguages();
settings->setValue("general/systemLang", langs.isEmpty() ? "" : langs.first().left(2).toLower());
settings->setValue("general/systemUnits", l.measurementSystem() == QLocale::MetricSystem ? "metric" : "imperial");
settings->setValue("general/temperatureUnit", l.measurementSystem() == QLocale::MetricSystem ? "c" : "f");
}
QNetworkAccessManager* nam = new QNetworkAccessManager();
NetworkDataController* ndc = new NetworkDataController(nam);
OwmController* wc = new OwmController(ndc, settings);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("NetworkDataController", ndc);
engine.rootContext()->setContextProperty("OwmController", wc);
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
int rt = app.exec();
settings->sync();
qDeleteAll(engine.rootObjects());
delete wc;
delete ndc;
delete nam;
delete settings;
return rt;
}