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#ifndef QSYSTEMERROR_P_H
5#define QSYSTEMERROR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include <qstring.h>
20
21QT_BEGIN_NAMESPACE
22
23class QSystemError
24{
25public:
26 enum ErrorScope
27 {
28 NoError,
29 StandardLibraryError,
30 NativeError
31 };
32
33 constexpr explicit QSystemError(int error, ErrorScope scope)
34 : errorCode(error), errorScope(scope)
35 {
36 }
37 constexpr QSystemError() = default;
38
39 QString toString() const { return string(errorScope, errorCode); }
40 constexpr ErrorScope scope() const { return errorScope; }
41 constexpr int error() const { return errorCode; }
42
43 constexpr bool ok() const noexcept { return errorScope == NoError; }
44 static constexpr QSystemError stdError(int error)
45 { return QSystemError(error, StandardLibraryError); }
46
47 static Q_CORE_EXPORT QString string(ErrorScope errorScope, int errorCode);
48 static Q_CORE_EXPORT QString stdString(int errorCode = -1);
49#ifdef Q_OS_WIN
50 static Q_CORE_EXPORT QString windowsString(int errorCode = -1);
51 using HRESULT = long;
52 static Q_CORE_EXPORT QString windowsComString(HRESULT hr);
53
54 static constexpr QSystemError nativeError(int error)
55 { return QSystemError(error, NativeError); }
56#endif
57
58 // data members
59 int errorCode = 0;
60 ErrorScope errorScope = NoError;
61};
62
63QT_END_NAMESPACE
64
65#endif // QSYSTEMERROR_P_H
66

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/corelib/kernel/qsystemerror_p.h