-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
66 lines (54 loc) · 1.97 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
62
63
64
65
66
#include <QApplication>
#include <QQmlApplicationEngine>
#include "triggerclient.h"
#include "triggerserver.h"
#include <QtQml>
#include <QCommandLineParser>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QCommandLineParser parser;
app.setApplicationVersion("2.0");
parser.setApplicationDescription("synchronized image viewer");
parser.addHelpOption();
parser.addVersionOption();
parser.addOptions({
{{"c" , "client"},
"run in client mode with specified master",
"client"},
{{"p" , "port"},
"UDP port, used by the master application",
"port",
"5555"},
{{"i" , "interval"},
"image change interval (ignored in client mode)",
"interval",
"1"}
});
parser.process(app);
bool parseOk;
quint16 port = parser.value("port").toInt(&parseOk);
if(!parseOk) {
qFatal("Invalid port given!");
}
int interval = parser.value("interval").toInt(&parseOk);
if(!parseOk) {
qFatal("Invalid interval given!");
}
QQmlApplicationEngine engine;
QObject *trigger = nullptr;
if(parser.isSet("client")) {
QString masterAddress = parser.value("client");
qDebug() << "starting client with master at" << masterAddress << port;
trigger = new TriggerClient(QHostAddress(masterAddress), port);
} else {
qDebug() << "starting master listening at port " << port;
trigger = new TriggerServer(interval, port);
}
engine.rootContext()->setContextProperty("trigger", trigger);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}