-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (48 loc) · 1.39 KB
/
Copy pathmain.cpp
File metadata and controls
73 lines (48 loc) · 1.39 KB
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
67
68
69
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QHttpServer>
#include <QHttpServerResponse>
#include <QFile>
#include <QJsonObject>
#include <QJsonDocument>
void startHttpServer(QHttpServer* s){
s->route("/", []() {
return "Hello world";
});
s->route("/start", [](){
qDebug() << "START";
return "Starting TEST!";
} );
s->route("/getResult", [] {
qDebug() << "GET RESULT";
qDebug() <<"JSON result: ";
QJsonObject so={
{"key1", "1"},
{"key2", "2"},
{"key3", "3"}
};
qDebug()<<so;
return so;
});
const auto port = s->listen(QHostAddress::Any);
qInfo().noquote()
<< QCoreApplication::translate("QHttpServerExample",
"Running on http://127.0.0.1:%1/"
"(Press CTRL+C to quit)").arg(port);
}
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/HTTPserver/Main.qml"_qs);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.load(url);
QHttpServer httpServer;
startHttpServer(&httpServer);
return app.exec();
}