File: main.cpp

package info (click to toggle)
qt6-remoteobjects 6.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,812 kB
  • sloc: cpp: 20,883; sh: 29; makefile: 26
file content (68 lines) | stat: -rw-r--r-- 2,028 bytes parent folder | download | duplicates (2)
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
// Copyright (C) 2019 Ford Motor Company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QTreeView>
#include <QApplication>
#include <QRemoteObjectNode>
#include <QAbstractItemModelReplica>
#include <QWebSocket>

#ifndef QT_NO_SSL
# include <QFile>
# include <QSslConfiguration>
# include <QSslKey>
#endif
#include "websocketiodevice.h"

int main(int argc, char **argv)
{

    QLoggingCategory::setFilterRules("qt.remoteobjects.debug=false\n"
                                     "qt.remoteobjects.warning=false\n"
                                     "qt.remoteobjects.models.debug=false\n"
                                     "qt.remoteobjects.models.debug=false");

    QApplication app(argc, argv);

    //! [0]
    QScopedPointer<QWebSocket> webSocket{new QWebSocket};
    WebSocketIoDevice socket(webSocket.data());
//! [0]

//! [1]
#ifndef QT_NO_SSL
    // Always use secure connections when available
    QSslConfiguration sslConf;
    QFile certFile(QStringLiteral(":/sslcert/client.crt"));
    if (!certFile.open(QIODevice::ReadOnly))
        qFatal("Can't open client.crt file");
    sslConf.setLocalCertificate(QSslCertificate{certFile.readAll()});

    QFile keyFile(QStringLiteral(":/sslcert/client.key"));
    if (!keyFile.open(QIODevice::ReadOnly))
        qFatal("Can't open client.key file");
    sslConf.setPrivateKey(QSslKey{keyFile.readAll(), QSsl::Rsa});

    sslConf.setPeerVerifyMode(QSslSocket::VerifyPeer);
    webSocket->setSslConfiguration(sslConf);
#endif
    //! [1]

    //! [2]
    QRemoteObjectNode node;
    node.addClientSideConnection(&socket);
    node.setHeartbeatInterval(1000);
    webSocket->open(QStringLiteral("ws://localhost:8088"));
    //! [2]

    //! [3]
    QTreeView view;
    view.setWindowTitle(QStringLiteral("RemoteView"));
    view.resize(640,480);
    QScopedPointer<QAbstractItemModelReplica> model(node.acquireModel(QStringLiteral("RemoteModel")));
    view.setModel(model.data());
    view.show();

    return app.exec();
    //! [3]
}