-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
57 lines (46 loc) · 1.75 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
#include <QDebug>
#include <QFile>
#include <QFont>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "usermodel.h"
int main(int argc, char *argv[])
{
// Force printf calls to stdout to be printed immediately.
setbuf(stdout, NULL);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QFont font("Arial");
font.setWeight(QFont::Light);
app.setFont(font);
// Read configuration arguments from "config.txt" in the same directory as the exectuable.
QString connectionString;
QString devId;
const QString configFilePath = app.applicationDirPath() + QStringLiteral("/config.txt");
QFile file(configFilePath);
if (file.open(QIODevice::ReadOnly)) {
QByteArray contents = file.readAll();
QList<QByteArray> configArgs = contents.split('\n');
bool configFormatError = false;
if (configArgs.size() >= 2) {
connectionString = configArgs.at(0);
devId = configArgs.at(1);
if (connectionString.isEmpty() || devId.isEmpty())
configFormatError = true;
} else {
configFormatError = true;
}
if (configFormatError) {
qWarning() << "Expected <connectionString>\\n<devId> in config.txt, but found:" << contents
<< "\nRunning in offline mode";
}
} else {
qWarning().nospace() << "No config.txt found at " << configFilePath << "; running in offline mode";
}
UserModel userModel(connectionString, devId);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("userModel", &userModel);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}