12# include <qt_windows.h>
15#ifndef QT_BOOTSTRAPPED
16# include <qcoreapplication.h>
21using namespace Qt::StringLiterals;
23#if !defined(Q_OS_WIN) && QT_CONFIG(thread) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) &&
24 defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L
35 [[maybe_unused]]
static inline QString fromstrerror_helper(
int,
const QByteArray &buf)
37 return QString::fromLocal8Bit(buf);
39 [[maybe_unused]]
static inline QString fromstrerror_helper(
const char *str,
const QByteArray &)
41 return QString::fromLocal8Bit(str);
47static QString windowsErrorString(
int errorCode)
50 wchar_t *string =
nullptr;
51 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
54 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
58 ret = QString::fromWCharArray(string);
59 LocalFree((HLOCAL)string);
61 if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
62 ret = QString::fromLatin1(
"The specified module could not be found.");
63 if (ret.endsWith(
"\r\n"_L1))
66 ret = QString::fromLatin1(
"Unknown error 0x%1.")
67 .arg(
unsigned(errorCode), 8, 16,
'0'_L1);
74 const char *s =
nullptr;
80 s = QT_TRANSLATE_NOOP(
"QIODevice",
"Permission denied");
83 s = QT_TRANSLATE_NOOP(
"QIODevice",
"Too many open files");
86 s = QT_TRANSLATE_NOOP(
"QIODevice",
"No such file or directory");
89 s = QT_TRANSLATE_NOOP(
"QIODevice",
"No space left on device");
92 #if QT_CONFIG(thread) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L
&& !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
93 QByteArray buf(1024, Qt::Uninitialized);
94 ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
96 ret = QString::fromLocal8Bit(strerror(errorCode));
101#ifndef QT_BOOTSTRAPPED
102 ret = QCoreApplication::translate(
"QIODevice", s);
104 ret = QString::fromLatin1(s);
107 return ret.trimmed();
112 switch (errorScope) {
115 return windowsErrorString(errorCode);
117 case StandardLibraryError:
118 return standardLibraryErrorString(errorCode);
120 qWarning(
"invalid error scope");
123 return u"No error"_s;
129 return standardLibraryErrorString(errorCode == -1 ? errno : errorCode);
133QString QSystemError::windowsString(
int errorCode)
135 return windowsErrorString(errorCode == -1 ? GetLastError() : errorCode);
138QString QSystemError::windowsComString(HRESULT hr)
140 const _com_error comError(hr);
141 QString result = u"COM error 0x"_s + QString::number(ulong(hr), 16);
142 if (
const wchar_t *msg = comError.ErrorMessage())
143 result += u": "_s + QString::fromWCharArray(msg);
147QString qt_error_string(
int code)
149 return windowsErrorString(code == -1 ? GetLastError() : code);
154 return standardLibraryErrorString(code == -1 ? errno : code);
Combined button and popup list for selecting options.
QString qt_error_string(int code)
static QString standardLibraryErrorString(int errorCode)