-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
95 lines (67 loc) · 2.02 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QHostInfo>
#include <QQmlContext>
#include <QNetworkInterface>
#include <QStringList>
#include "server.h"
#include "client.h"
class ApplicationData : public QObject
{
Q_OBJECT
public:
Server *oServer;
Client *oClient;
bool bServer=false;
QObject *oQml;
void setQmlObject(QObject *oQml_){
oQml=oQml_;
}
Q_INVOKABLE void connectServer(QString port_){
oServer=new Server(port_,true,oQml);
bServer=true;
}
Q_INVOKABLE void disconnectServer(){
if(bServer){
oServer->disconnect();
}
}
Q_INVOKABLE void connectClient(QString url_){
oClient =new Client(url_,true,oQml);
}
Q_INVOKABLE void disconnectClient(){
oClient->disconnect();
}
Q_INVOKABLE void sendMessage(QString text_){
oClient->sendT(text_);
}
Q_INVOKABLE QString getIp() const {
QStringList addresses;
foreach(QHostAddress address, QNetworkInterface::allAddresses())
{
// Filtre les adresses localhost ...
if(address != QHostAddress::LocalHostIPv6
&& address != QHostAddress::LocalHost
// ... APIPA ...
&& !address.isInSubnet(QHostAddress::parseSubnet("169.254.0.0/16"))
// ... Lien Local IPv6
&& !address.isInSubnet(QHostAddress::parseSubnet("FE80::/64")))
{
addresses << address.toString();
}
}
return addresses[0];
}
};
int main(int argc, char *argv[]){
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
ApplicationData data;
engine.rootContext()->setContextProperty("applicationData", &data);
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
QList<QObject*> rootObjt=engine.rootObjects();
data.setQmlObject( rootObjt[0] );
return app.exec();
}
#include "main.moc"