summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
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 /src/network/kernel
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 'src/network/kernel')
-rw-r--r--src/network/kernel/qnetconmonitor_win.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp
index 22bbed2bea..64bd90b0ad 100644
--- a/src/network/kernel/qnetconmonitor_win.cpp
+++ b/src/network/kernel/qnetconmonitor_win.cpp
@@ -9,6 +9,7 @@
#include <QtCore/qmetaobject.h>
#include <QtCore/private/qfunctions_win_p.h>
+#include <QtCore/private/qsystemerror_p.h>
#include <QtNetwork/qnetworkinterface.h>
@@ -16,7 +17,6 @@
#include <netlistmgr.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
-#include <comdef.h>
#include <iphlpapi.h>
#include <algorithm>
@@ -28,12 +28,6 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcNetMon, "qt.network.monitor");
namespace {
-QString errorStringFromHResult(HRESULT hr)
-{
- _com_error error(hr);
- return QString::fromWCharArray(error.ErrorMessage());
-}
-
template<typename T>
bool QueryInterfaceImpl(IUnknown *from, REFIID riid, void **ppvObject)
{
@@ -150,7 +144,7 @@ QNetworkConnectionEvents::QNetworkConnectionEvents(QNetworkConnectionMonitorPriv
IID_INetworkListManager, &networkListManager);
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Could not get a NetworkListManager instance:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
return;
}
@@ -162,7 +156,7 @@ QNetworkConnectionEvents::QNetworkConnectionEvents(QNetworkConnectionMonitorPriv
}
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Failed to get connection point for network events:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
}
}
@@ -177,7 +171,7 @@ ComPtr<INetworkConnection> QNetworkConnectionEvents::getNetworkConnectionFromAda
auto hr = networkListManager->GetNetworkConnections(connections.GetAddressOf());
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Failed to enumerate network connections:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
return nullptr;
}
ComPtr<INetworkConnection> connection = nullptr;
@@ -185,7 +179,7 @@ ComPtr<INetworkConnection> QNetworkConnectionEvents::getNetworkConnectionFromAda
hr = connections->Next(1, connection.GetAddressOf(), nullptr);
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Failed to get next network connection in enumeration:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
break;
}
if (connection) {
@@ -193,7 +187,7 @@ ComPtr<INetworkConnection> QNetworkConnectionEvents::getNetworkConnectionFromAda
hr = connection->GetAdapterId(&adapterId);
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Failed to get adapter ID from network connection:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
continue;
}
if (guid == adapterId)
@@ -258,7 +252,8 @@ bool QNetworkConnectionEvents::setTarget(const QNetworkInterface &iface)
}
auto hr = connection->GetConnectionId(&guid);
if (FAILED(hr)) {
- qCDebug(lcNetMon) << "Failed to get the connection's GUID:" << errorStringFromHResult(hr);
+ qCDebug(lcNetMon) << "Failed to get the connection's GUID:"
+ << QSystemError::windowsComString(hr);
return false;
}
currentConnectionId = guid;
@@ -281,7 +276,7 @@ bool QNetworkConnectionEvents::startMonitoring()
auto hr = connectionPoint->Advise(this, &cookie);
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Failed to subscribe to network connectivity events:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
return false;
}
return true;
@@ -292,7 +287,7 @@ bool QNetworkConnectionEvents::stopMonitoring()
auto hr = connectionPoint->Unadvise(cookie);
if (FAILED(hr)) {
qCDebug(lcNetMon) << "Failed to unsubscribe from network connection events:"
- << errorStringFromHResult(hr);
+ << QSystemError::windowsComString(hr);
return false;
}
cookie = 0;