-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
59 lines (40 loc) · 1.52 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
#include "QtWebChannel/qwebchannel.h"
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtWebSockets/QWebSocketServer>
#include <QCoreApplication>
#include <QUrl>
#include <QDebug>
#include <QDesktopServices>
#include <QGuiApplication>
#include <qtwebengineglobal.h>
#include<websockettransport.h>
#include<websocketclientwrapper.h>
#include <dbserver.h>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtWebEngine::initialize();
QWebSocketServer server(QStringLiteral("QWebChannel Standalone Example Server"),
QWebSocketServer::NonSecureMode);
if (!server.listen(QHostAddress::LocalHost, 12345)) {
qFatal("Failed to open web socket server.");
return 1;
}
// wrap WebSocket clients in QWebChannelAbstractTransport objects
WebSocketClientWrapper clientWrapper(&server);
// setup the channel
QWebChannel channel;
QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected,
&channel, &QWebChannel::connectTo);
// setup the dialog and publish it to the QWebChannel
DBServer* dbserver = new DBServer(&app);
channel.registerObject("dbserver", dbserver);
//Open in browser
//QUrl url = QUrl::fromLocalFile("C:/Users/vbhardwa/Documents/QT/HTMLQtApp/index.html");//(BUILD_DIR "/index.html");
//QDesktopServices::openUrl(url);
//Open in webview
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}