From f7fd57075be0f504cad46e9a2e78caf3d54979af Mon Sep 17 00:00:00 2001 From: Mike Achtelik Date: Mon, 18 Oct 2021 13:35:15 +0200 Subject: Introduce Q_APPLICATION_STATIC QObjects must be deleted if the QCoreApplication is being destroyed. This was previously done by implementing custom code in qtbase and other modules. So unify it and introduce a Q_APPLICATION_STATIC, based on the Q_GLOBAL_STATIC, which centralises the logic. Since we still have a few remaining living QObjects, this comes in handy to fix those as well. Task-number: QTBUG-84234 Change-Id: I3040a2280ff56291f2b1c39948c06a23597865c4 Reviewed-by: Thiago Macieira --- src/network/kernel/qhostinfo.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'src/network/kernel/qhostinfo.cpp') diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index fdf2844447..6f508fb59b 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -43,6 +43,7 @@ #include "qhostinfo_p.h" #include +#include "QtCore/qapplicationstatic.h" #include "QtCore/qscopedpointer.h" #include #include @@ -99,24 +100,7 @@ std::pair separate_if(InputIt first, InputIt last, OutputI return std::make_pair(dest1, dest2); } -QHostInfoLookupManager* theHostInfoLookupManager() -{ - static QHostInfoLookupManager* theManager = nullptr; - static QBasicMutex theMutex; - - const QMutexLocker locker(&theMutex); - if (theManager == nullptr) { - theManager = new QHostInfoLookupManager(); - Q_ASSERT(QCoreApplication::instance()); - QObject::connect(QCoreApplication::instance(), &QCoreApplication::destroyed, [] { - const QMutexLocker locker(&theMutex); - delete theManager; - theManager = nullptr; - }); - } - - return theManager; -} +Q_APPLICATION_STATIC(QHostInfoLookupManager, theHostInfoLookupManager) } -- cgit v1.2.3