summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2021-04-13 17:01:38 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-14 22:45:22 +0000
commit4e8e92f640d50163d73caff7a188280ffd6bddcc (patch)
treeba65b53ebc02853b132a703fe8333ab23ae4186c /src/network
parenta474d8a9be11f840c26d8a12586b9d11b6027015 (diff)
QNetworkInformation: delete the instance as a post-routine
On Windows, on exit, the backend will deref (and then implicitly start deletion of) a COM object. This object tries to communicate with an object in another thread, though it seems this other thread quits before the main thread in _most_ cases. To get around this we move the deletion to earlier in the program. While this is only reported as a Windows issue it makes for more consistent behavior if all platforms behave the same. Document and test that recreation of QNI works as expected after the destruction (and recreation) of QCoreApplication. Amends: 0875626e22ad4e709ddf505e701a8d699559f5b4 Fixes: QTBUG-92568 Change-Id: Iffc07f38673019aa059efd4d64d2ad706a03f6fe Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit e875c071ec32ab9aa460c982f25f6c6191e41326) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/kernel/qnetworkinformation.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/network/kernel/qnetworkinformation.cpp b/src/network/kernel/qnetworkinformation.cpp
index 6ce572d408..c36b1c4698 100644
--- a/src/network/kernel/qnetworkinformation.cpp
+++ b/src/network/kernel/qnetworkinformation.cpp
@@ -46,6 +46,7 @@
#include <QtCore/private/qobject_p.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qmutex.h>
+#include <QtCore/qthread.h>
#include <QtCore/private/qfactoryloader_p.h>
#include <algorithm>
@@ -73,11 +74,30 @@ struct QStaticNetworkInformationDataHolder
};
Q_GLOBAL_STATIC(QStaticNetworkInformationDataHolder, dataHolder);
+static void networkInfoCleanup()
+{
+ if (!dataHolder.exists())
+ return;
+ QMutexLocker locker(&dataHolder->instanceMutex);
+ QNetworkInformation *instance = dataHolder->instanceHolder.get();
+ if (!instance)
+ return;
+
+ auto needsReinvoke = instance->thread() && instance->thread() != QThread::currentThread();
+ if (needsReinvoke) {
+ QMetaObject::invokeMethod(dataHolder->instanceHolder.get(), []() { networkInfoCleanup(); });
+ return;
+ }
+ dataHolder->instanceHolder.reset();
+}
+
class QNetworkInformationPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QNetworkInformation)
public:
- QNetworkInformationPrivate(QNetworkInformationBackend *backend) : backend(backend) { }
+ QNetworkInformationPrivate(QNetworkInformationBackend *backend) : backend(backend) {
+ qAddPostRoutine(&networkInfoCleanup);
+ }
static QNetworkInformation *create(QNetworkInformation::Features features);
static QNetworkInformation *create(QStringView name);
@@ -408,7 +428,9 @@ QNetworkInformationBackendFactory::~QNetworkInformationBackendFactory()
you can load() plugins based on which features are needed.
QNetworkInformation is a singleton and stays alive from the first
- successful load() until application shutdown.
+ successful load() until destruction of the QCoreApplication object.
+ If you destroy and re-create the QCoreApplication object you must call
+ load() again.
\sa QNetworkInformation::Feature
*/