Simplify QNetworkListManagerNetworkInformationBackend's COM handling
The class used to be implicitly movable to a different thread, but this is no longer the case, so we don't need to initialize and uninitialize the COM library in start() and stop(). A qFatal has been added to ensure we detect if this will be required again. Change-Id: Ib22fe0bdcd5cb96f05632b09803c5de8ff43279a Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
927bb089f7
commit
ee81e1acf4
@ -143,6 +143,7 @@ QNetworkListManagerNetworkInformationBackend::~QNetworkListManagerNetworkInforma
|
||||
if (comInitFailed)
|
||||
return;
|
||||
stop();
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
void QNetworkListManagerNetworkInformationBackend::setConnectivity(NLM_CONNECTIVITY newConnectivity)
|
||||
@ -164,11 +165,8 @@ void QNetworkListManagerNetworkInformationBackend::checkCaptivePortal()
|
||||
|
||||
bool QNetworkListManagerNetworkInformationBackend::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::ThreadChange && monitoring) {
|
||||
stop();
|
||||
QMetaObject::invokeMethod(this, &QNetworkListManagerNetworkInformationBackend::start,
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
if (event->type() == QEvent::ThreadChange)
|
||||
qFatal("Moving QNetworkListManagerNetworkInformationBackend to different thread is not supported");
|
||||
|
||||
return QObject::event(event);
|
||||
}
|
||||
@ -177,15 +175,9 @@ bool QNetworkListManagerNetworkInformationBackend::start()
|
||||
{
|
||||
Q_ASSERT(!monitoring);
|
||||
|
||||
if (comInitFailed) {
|
||||
auto hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
if (FAILED(hr)) {
|
||||
qCWarning(lcNetInfoNLM) << "Failed to initialize COM:" << errorStringFromHResult(hr);
|
||||
comInitFailed = true;
|
||||
return false;
|
||||
}
|
||||
comInitFailed = false;
|
||||
}
|
||||
if (comInitFailed)
|
||||
return false;
|
||||
|
||||
if (!managerEvents)
|
||||
managerEvents = new QNetworkListManagerEvents();
|
||||
|
||||
@ -203,9 +195,6 @@ void QNetworkListManagerNetworkInformationBackend::stop()
|
||||
monitoring = false;
|
||||
managerEvents.Reset();
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
comInitFailed = true; // we check this value in start() to see if we need to re-initialize
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user