diff options
author | Mike Achtelik <mike.achtelik@gmail.com> | 2021-10-18 13:35:15 +0200 |
---|---|---|
committer | Mike Achtelik <mike.achtelik@gmail.com> | 2021-11-18 20:53:27 +0100 |
commit | f7fd57075be0f504cad46e9a2e78caf3d54979af (patch) | |
tree | ed0c4739aff627488746d6fc973e4aee9da7ba33 /src/network/kernel/qhostinfo.cpp | |
parent | 1a8b7eb1d4f27e74621ee94c01dbeda3afd302c7 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/kernel/qhostinfo.cpp')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 20 |
1 files changed, 2 insertions, 18 deletions
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 <qplatformdefs.h> +#include "QtCore/qapplicationstatic.h" #include "QtCore/qscopedpointer.h" #include <qabstracteventdispatcher.h> #include <qcoreapplication.h> @@ -99,24 +100,7 @@ std::pair<OutputIt1, OutputIt2> 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) } |