diff options
Diffstat (limited to 'src/corelib/kernel/qsystemerror.cpp')
-rw-r--r-- | src/corelib/kernel/qsystemerror.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/corelib/kernel/qsystemerror.cpp b/src/corelib/kernel/qsystemerror.cpp index 05edd9b5c3..428ce62984 100644 --- a/src/corelib/kernel/qsystemerror.cpp +++ b/src/corelib/kernel/qsystemerror.cpp @@ -9,6 +9,7 @@ #endif #ifdef Q_OS_WIN # include <qt_windows.h> +# include <comdef.h> #endif #ifndef QT_BOOTSTRAPPED # include <qcoreapplication.h> @@ -46,7 +47,7 @@ static QString windowsErrorString(int errorCode) { QString ret; wchar_t *string = nullptr; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), @@ -133,6 +134,15 @@ QString QSystemError::windowsString(int errorCode) return windowsErrorString(errorCode == -1 ? GetLastError() : errorCode); } +QString QSystemError::windowsComString(HRESULT hr) +{ + const _com_error comError(hr); + QString result = "COM error 0x"_L1 + QString::number(ulong(hr), 16); + if (const wchar_t *msg = comError.ErrorMessage()) + result += ": "_L1 + QString::fromWCharArray(msg); + return result; +} + QString qt_error_string(int code) { return windowsErrorString(code == -1 ? GetLastError() : code); |