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 | |
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')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 20 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_unix.cpp | 21 |
2 files changed, 5 insertions, 36 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) } diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index 9b0a2ee669..3ccf8b217b 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -53,6 +53,8 @@ #include <qfile.h> #include <private/qnet_unix_p.h> +#include "QtCore/qapplicationstatic.h" + #include <sys/types.h> #include <netdb.h> #include <arpa/inet.h> @@ -157,24 +159,7 @@ LibResolv::LibResolv() } } -LibResolv* libResolv() -{ - static LibResolv* theLibResolv = nullptr; - static QBasicMutex theMutex; - - const QMutexLocker locker(&theMutex); - if (theLibResolv == nullptr) { - theLibResolv = new LibResolv(); - Q_ASSERT(QCoreApplication::instance()); - QObject::connect(QCoreApplication::instance(), &QCoreApplication::destroyed, [] { - const QMutexLocker locker(&theMutex); - delete theLibResolv; - theLibResolv = nullptr; - }); - } - - return theLibResolv; -} +Q_APPLICATION_STATIC(LibResolv, libResolv) static void resolveLibrary(LibResolvFeature f) { |