Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdbusreply.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qdbusreply.h"
5#include "qdbusmetatype.h"
6#include "qdbusmetatype_p.h"
7#include <QDebug>
8
9#ifndef QT_NO_DBUS
10
12
13using namespace Qt::StringLiterals;
14
164{
166
167 if (error.isValid()) {
168 data = QVariant(); // clear it
169 return;
170 }
171
172 if (reply.arguments().size() >= 1 && reply.arguments().at(0).metaType() == data.metaType()) {
173 data = reply.arguments().at(0);
174 return;
175 }
176
177 const char *expectedSignature = QDBusMetaType::typeToSignature(data.metaType());
178 const char *receivedType = nullptr;
179 QByteArray receivedSignature;
180
181 if (reply.arguments().size() >= 1) {
182 if (reply.arguments().at(0).metaType() == QDBusMetaTypeId::argument()) {
183 // compare signatures instead
184 QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));
185 receivedSignature = arg.currentSignature().toLatin1();
186 if (receivedSignature == expectedSignature) {
187 // matched. Demarshall it
188 QDBusMetaType::demarshall(arg, data.metaType(), data.data());
189 return;
190 }
191 } else {
192 // not an argument and doesn't match?
193 QMetaType type = reply.arguments().at(0).metaType();
194 receivedType = type.name();
195 receivedSignature = QDBusMetaType::typeToSignature(type);
196 }
197 }
198
199 // error
200 if (receivedSignature.isEmpty())
201 receivedSignature = "<empty signature>";
202 QString errorMsg;
203 if (receivedType) {
204 errorMsg = "Unexpected reply signature: got \"%1\" (%4), expected \"%2\" (%3)"_L1
205 .arg(QLatin1StringView(receivedSignature),
206 QLatin1StringView(expectedSignature),
207 QLatin1StringView(data.typeName()),
208 QLatin1StringView(receivedType));
209 } else {
210 errorMsg = "Unexpected reply signature: got \"%1\", expected \"%2\" (%3)"_L1
211 .arg(QLatin1StringView(receivedSignature),
212 QLatin1StringView(expectedSignature),
213 QLatin1StringView(data.typeName()));
214 }
215
217 data = QVariant(); // clear it
218}
219
221
222#endif // QT_NO_DBUS
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtDBus
\inmodule QtDBus
Definition qdbuserror.h:21
@ InvalidSignature
Definition qdbuserror.h:43
\inmodule QtDBus
static bool demarshall(const QDBusArgument &, QMetaType id, void *data)
static const char * typeToSignature(QMetaType type)
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
\inmodule QtCore
Definition qmetatype.h:341
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8870
\inmodule QtCore
Definition qvariant.h:65
QMetaType argument()
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
SSL_CTX int void * arg
QNetworkReply * reply