summaryrefslogtreecommitdiffstats
path: root/qmake
diff options
context:
space:
mode:
authorYuhang Zhao <2546789017@qq.com>2022-10-26 13:34:35 +0800
committerYuhang Zhao <2546789017@qq.com>2022-11-16 19:44:43 +0800
commitbd7fa4a53791ead147393d3a4a797d2e14ee3343 (patch)
treeef50df5bf2a48546bfe0ac3d884f244c458d0d9c /qmake
parente2f895db2eb80f2735e89763a047571410565369 (diff)
Windows: centralize how we handle error messages
Currently QtBase contains multiple implementation of how to get the Win32 and COM error messages, and they are almost exactly the same, what's worse, Qt already has a private QSystemError class to do such things, so we are re-inventing the wheel in many places. This patch removes all other custom error message implementations besides the QSystemError one. And since there are a lot of places need the COM error message, move the implementation to QSystemError so that it can handle both Win32 error and COM error. Since I'm touching these lines anyway, break them into short lines if they are above the length limit. Change-Id: I1067c874011800303f0f114b5cb8830ac6810fc0 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'qmake')
-rw-r--r--qmake/library/ioutils.cpp24
1 files changed, 5 insertions, 19 deletions
diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp
index 71bf0020c0..38bb246341 100644
--- a/qmake/library/ioutils.cpp
+++ b/qmake/library/ioutils.cpp
@@ -9,6 +9,7 @@
#ifdef Q_OS_WIN
# include <qt_windows.h>
+# include <private/qsystemerror_p.h>
#else
# include <sys/types.h>
# include <sys/stat.h>
@@ -212,23 +213,6 @@ QString IoUtils::shellQuoteWin(const QString &arg)
#if defined(PROEVALUATOR_FULL)
-# if defined(Q_OS_WIN)
-static QString windowsErrorCode()
-{
- wchar_t *string = nullptr;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPWSTR)&string,
- 0,
- NULL);
- QString ret = QString::fromWCharArray(string);
- LocalFree((HLOCAL)string);
- return ret.trimmed();
-}
-# endif
-
bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceFileName, QString *errorString)
{
# ifdef Q_OS_UNIX
@@ -255,7 +239,8 @@ bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceF
GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (rHand == INVALID_HANDLE_VALUE) {
- *errorString = fL1S("Cannot open reference file %1: %2").arg(referenceFileName, windowsErrorCode());
+ *errorString = fL1S("Cannot open reference file %1: %2")
+ .arg(referenceFileName, QSystemError::windowsString());
return false;
}
FILETIME ft;
@@ -265,7 +250,8 @@ bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceF
GENERIC_WRITE, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (wHand == INVALID_HANDLE_VALUE) {
- *errorString = fL1S("Cannot open %1: %2").arg(targetFileName, windowsErrorCode());
+ *errorString = fL1S("Cannot open %1: %2")
+ .arg(targetFileName, QSystemError::windowsString());
return false;
}
SetFileTime(wHand, NULL, NULL, &ft);