blob: b73712ebda3ae147717dd785d09f83587bef2ff2 (
plain)
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
|
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "testtransport.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
QT_BEGIN_NAMESPACE
TestTransport::TestTransport(QObject *parent)
: QWebChannelAbstractTransport(parent)
{
}
void TestTransport::sendMessage(const QJsonObject &message)
{
emit sendMessageRequested(message);
}
void TestTransport::receiveMessage(const QString &message)
{
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error);
if (error.error) {
qWarning("Failed to parse JSON message: %s\nError is: %s",
qPrintable(message), qPrintable(error.errorString()));
return;
} else if (!doc.isObject()) {
qWarning("Received JSON message that is not an object: %s",
qPrintable(message));
return;
}
emit messageReceived(doc.object(), this);
}
QT_END_NAMESPACE
|