Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qdbuserror.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 "qdbuserror.h"
5
6#include <qdebug.h>
7#include <qvarlengtharray.h>
8#include <private/qoffsetstringarray_p.h>
9
10#ifndef QT_BOOTSTRAPPED
11#include "qdbus_symbols_p.h"
12#include "qdbusmessage.h"
13#include "qdbusmessage_p.h"
14#endif
15
16#ifndef QT_NO_DBUS
17
19
21
22static constexpr const auto errorMessages = qOffsetStringArray(
23 "NoError",
24 "other",
25 "org.freedesktop.DBus.Error.Failed",
26 "org.freedesktop.DBus.Error.NoMemory",
27 "org.freedesktop.DBus.Error.ServiceUnknown",
28 "org.freedesktop.DBus.Error.NoReply",
29 "org.freedesktop.DBus.Error.BadAddress",
30 "org.freedesktop.DBus.Error.NotSupported",
31 "org.freedesktop.DBus.Error.LimitsExceeded",
32 "org.freedesktop.DBus.Error.AccessDenied",
33 "org.freedesktop.DBus.Error.NoServer",
34 "org.freedesktop.DBus.Error.Timeout",
35 "org.freedesktop.DBus.Error.NoNetwork",
36 "org.freedesktop.DBus.Error.AddressInUse",
37 "org.freedesktop.DBus.Error.Disconnected",
38 "org.freedesktop.DBus.Error.InvalidArgs",
39 "org.freedesktop.DBus.Error.UnknownMethod",
40 "org.freedesktop.DBus.Error.TimedOut",
41 "org.freedesktop.DBus.Error.InvalidSignature",
42 "org.freedesktop.DBus.Error.UnknownInterface",
43 "org.freedesktop.DBus.Error.UnknownObject",
44 "org.freedesktop.DBus.Error.UnknownProperty",
45 "org.freedesktop.DBus.Error.PropertyReadOnly",
46 "org.qtproject.QtDBus.Error.InternalError",
47 "org.qtproject.QtDBus.Error.InvalidService",
48 "org.qtproject.QtDBus.Error.InvalidObjectPath",
49 "org.qtproject.QtDBus.Error.InvalidInterface",
50 "org.qtproject.QtDBus.Error.InvalidMember",
51 ""
52);
53
54#ifndef QT_BOOTSTRAPPED
55static inline QDBusError::ErrorType get(const char *name)
56{
57 if (!name || !*name)
59 for (int i = 0; i < errorMessages.count(); ++i)
60 if (strcmp(name, errorMessages.at(i)) == 0)
62 return QDBusError::Other;
63}
64#endif
65
161 : code(NoError)
162{
163 // ### This class has an implicit (therefore inline) destructor
164 // so the following field cannot be used.
165 Q_UNUSED(unused);
166}
167
168#ifndef QT_BOOTSTRAPPED
174 : code(NoError)
175{
176 if (!error || !q_dbus_error_is_set(error))
177 return;
178
179 code = get(error->name);
180 msg = QString::fromUtf8(error->message);
181 nm = QString::fromUtf8(error->name);
182}
183
189 : code(NoError)
190{
191 if (qdmsg.type() != QDBusMessage::ErrorMessage)
192 return;
193
194 code = get(qdmsg.errorName().toUtf8().constData());
195 nm = qdmsg.errorName();
196 msg = qdmsg.errorMessage();
197}
198#endif
199
205 : code(error)
206{
208 msg = mess;
209}
210
216 : code(other.code), msg(other.msg), nm(other.nm)
217{
218}
219
226{
227 code = other.code;
228 msg = other.msg;
229 nm = other.nm;
230 return *this;
231}
232
233#ifndef QT_BOOTSTRAPPED
239{
240 if (qdmsg.type() == QDBusMessage::ErrorMessage) {
241 code = get(qdmsg.errorName().toUtf8().constData());
242 nm = qdmsg.errorName();
243 msg = qdmsg.errorMessage();
244 } else {
245 code =NoError;
246 nm.clear();
247 msg.clear();
248 }
249 return *this;
250}
251#endif
252
260{
261 return code;
262}
263
272{
273 return nm;
274}
275
283{
284 return msg;
285}
286
293{
294 return (code != NoError);
295}
296
302{
304}
305
306#ifndef QT_NO_DEBUG_STREAM
308{
309 QDebugStateSaver saver(dbg);
310 dbg.nospace() << "QDBusError(" << msg.name() << ", " << msg.message() << ')';
311 return dbg;
312}
313#endif
314
322
323#include "moc_qdbuserror.cpp"
324
325#endif // QT_NO_DBUS
326
327/*
328MSVC2015 has the warning C4503 at the end of the file:
329QtPrivate::StaticStringBuilder<QtPrivate::IndexesList<...> - decorated name length exceeded, name was truncated
330It is used by qOffsetStringArray in a constexpr evaluation and this code does not exist in the object file,
331but we still have the warning or even error with -WX flag
332*/
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
\inmodule QtDBus
Definition qdbuserror.h:21
QString message() const
Returns the message that the callee associated with this error.
static QString errorString(ErrorType error)
ErrorType
In order to facilitate verification of the most common D-Bus errors generated by the D-Bus implementa...
Definition qdbuserror.h:24
ErrorType type() const
Returns this error's ErrorType.
QDBusError & operator=(QDBusError &&other) noexcept
Definition qdbuserror.h:71
bool isValid() const
Returns true if this is a valid error condition (i.e., if there was an error), otherwise false.
QString name() const
Returns this error's name.
\inmodule QtDBus
QString errorName() const
Returns the name of the error that was received.
MessageType type() const
Returns the message type.
QString errorMessage() const
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5857
QByteArray toUtf8() const &
Definition qstring.h:563
Combined button and popup list for selecting options.
#define QT_WARNING_DISABLE_MSVC(number)
DBusConnection const char DBusError * error
static QDBusError::ErrorType get(const char *name)
static QT_BEGIN_NAMESPACE constexpr const auto errorMessages
QDebug operator<<(QDebug dbg, const QDBusError &msg)
#define QT_IMPL_METATYPE_EXTERN(TYPE)
Definition qmetatype.h:1369
constexpr auto qOffsetStringArray(const char(&...strings)[Nx]) noexcept
GLuint name
@ NoError
Definition main.cpp:34
#define Q_UNUSED(x)
QSharedPointer< T > other(t)
[5]