diff options
Diffstat (limited to 'src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp')
-rw-r--r-- | src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp index 5b0a91df3e..caa5046751 100644 --- a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp +++ b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp @@ -102,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 @@ -197,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) @@ -225,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) @@ -241,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) @@ -252,3 +264,5 @@ void QNetworkListManagerEvents::emitWinRTUpdates() #endif // QT_CONFIG(cpp_winrt) QT_END_NAMESPACE + +#include "moc_qnetworklistmanagerevents.cpp" |