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)
|
if (comInitFailed)
|
||||||
return;
|
return;
|
||||||
stop();
|
stop();
|
||||||
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QNetworkListManagerNetworkInformationBackend::setConnectivity(NLM_CONNECTIVITY newConnectivity)
|
void QNetworkListManagerNetworkInformationBackend::setConnectivity(NLM_CONNECTIVITY newConnectivity)
|
||||||
@ -164,11 +165,8 @@ void QNetworkListManagerNetworkInformationBackend::checkCaptivePortal()
|
|||||||
|
|
||||||
bool QNetworkListManagerNetworkInformationBackend::event(QEvent *event)
|
bool QNetworkListManagerNetworkInformationBackend::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::ThreadChange && monitoring) {
|
if (event->type() == QEvent::ThreadChange)
|
||||||
stop();
|
qFatal("Moving QNetworkListManagerNetworkInformationBackend to different thread is not supported");
|
||||||
QMetaObject::invokeMethod(this, &QNetworkListManagerNetworkInformationBackend::start,
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QObject::event(event);
|
return QObject::event(event);
|
||||||
}
|
}
|
||||||
@ -177,15 +175,9 @@ bool QNetworkListManagerNetworkInformationBackend::start()
|
|||||||
{
|
{
|
||||||
Q_ASSERT(!monitoring);
|
Q_ASSERT(!monitoring);
|
||||||
|
|
||||||
if (comInitFailed) {
|
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;
|
return false;
|
||||||
}
|
|
||||||
comInitFailed = false;
|
|
||||||
}
|
|
||||||
if (!managerEvents)
|
if (!managerEvents)
|
||||||
managerEvents = new QNetworkListManagerEvents();
|
managerEvents = new QNetworkListManagerEvents();
|
||||||
|
|
||||||
@ -203,9 +195,6 @@ void QNetworkListManagerNetworkInformationBackend::stop()
|
|||||||
monitoring = false;
|
monitoring = false;
|
||||||
managerEvents.Reset();
|
managerEvents.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
CoUninitialize();
|
|
||||||
comInitFailed = true; // we check this value in start() to see if we need to re-initialize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user