summaryrefslogtreecommitdiffstats
path: root/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp')
-rw-r--r--src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp
index 73691f0971..caa5046751 100644
--- a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp
+++ b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp
@@ -9,15 +9,7 @@
#include <mutex>
#if QT_CONFIG(cpp_winrt)
-#include <winrt/base.h>
-#include <QtCore/private/qfactorycacheregistration_p.h>
-// Workaround for Windows SDK bug.
-// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
-namespace winrt::impl
-{
- template <typename Async>
- auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout);
-}
+#include <QtCore/private/qt_winrtbase_p.h>
#include <winrt/Windows.Networking.Connectivity.h>
#endif // QT_CONFIG(cpp_winrt)
@@ -110,16 +102,22 @@ bool QNetworkListManagerEvents::start()
#if QT_CONFIG(cpp_winrt)
using namespace winrt::Windows::Networking::Connectivity;
using winrt::Windows::Foundation::IInspectable;
- // Register for changes in the network and store a token to unregister later:
- token = NetworkInformation::NetworkStatusChanged(
- [owner = QPointer(this)](const IInspectable sender) {
- Q_UNUSED(sender);
- if (owner) {
- std::scoped_lock locker(owner->winrtLock);
- if (owner->token)
- owner->emitWinRTUpdates();
- }
- });
+ try {
+ // Register for changes in the network and store a token to unregister later:
+ token = NetworkInformation::NetworkStatusChanged(
+ [owner = QPointer(this)](const IInspectable sender) {
+ Q_UNUSED(sender);
+ if (owner) {
+ std::scoped_lock locker(owner->winrtLock);
+ if (owner->token)
+ owner->emitWinRTUpdates();
+ }
+ });
+ } catch (const winrt::hresult_error &ex) {
+ qCWarning(lcNetInfoNLM) << "Failed to register network status changed callback:"
+ << QSystemError::windowsComString(ex.code());
+ }
+
// Emit initial state
emitWinRTUpdates();
#endif
@@ -172,7 +170,7 @@ bool QNetworkListManagerEvents::checkBehindCaptivePortal()
VariantInit(&variant);
const auto scopedVariantClear = qScopeGuard([&variant]() { VariantClear(&variant); });
- const wchar_t *versions[] = { NA_InternetConnectivityV6, NA_InternetConnectivityV4 };
+ const wchar_t *versions[] = { L"NA_InternetConnectivityV6", L"NA_InternetConnectivityV4" };
for (const auto version : versions) {
hr = propertyBag->Read(version, &variant, nullptr);
if (SUCCEEDED(hr)
@@ -205,7 +203,9 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile
NetworkAdapter adapter(nullptr);
try {
adapter = profile.NetworkAdapter();
- } catch (...) {
+ } catch (const winrt::hresult_error &ex) {
+ qCWarning(lcNetInfoNLM) << "Failed to obtain network adapter:"
+ << QSystemError::windowsComString(ex.code());
// pass, we will return Unknown anyway
}
if (adapter == nullptr)
@@ -233,7 +233,9 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile
ConnectionCost cost(nullptr);
try {
cost = profile.GetConnectionCost();
- } catch (...) {
+ } catch (const winrt::hresult_error &ex) {
+ qCWarning(lcNetInfoNLM) << "Failed to obtain connection cost:"
+ << QSystemError::windowsComString(ex.code());
// pass, we return false if we get an empty object back anyway
}
if (cost == nullptr)
@@ -249,7 +251,9 @@ void QNetworkListManagerEvents::emitWinRTUpdates()
ConnectionProfile profile = nullptr;
try {
profile = NetworkInformation::GetInternetConnectionProfile();
- } catch (...) {
+ } catch (const winrt::hresult_error &ex) {
+ qCWarning(lcNetInfoNLM) << "Failed to obtain connection profile:"
+ << QSystemError::windowsComString(ex.code());
// pass, we would just return early if we get an empty object back anyway
}
if (profile == nullptr)
@@ -260,3 +264,5 @@ void QNetworkListManagerEvents::emitWinRTUpdates()
#endif // QT_CONFIG(cpp_winrt)
QT_END_NAMESPACE
+
+#include "moc_qnetworklistmanagerevents.cpp"