QNetworkInformation[Win]: Catch potential WinRT exceptions
Some Windows SDKs seem to throw an exception from winrt::check_hresult() We need to handle this accordingly. Catch the exception and print relevant warning. Fixes: QTBUG-110408 Pick-to: 6.5 Change-Id: I1434ec425f0d0e597308b53f25f4f15049640060 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
79ac430537
commit
5564b166a3
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user