From 7297cd808b142c522d7d6bcfa30bf61a3a25127c Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 24 Jun 2023 12:36:50 +0200 Subject: [PATCH] QtCore: code tidies: use the 4-arg connect overload The 3-arg connect is error-prone and makes the lifetime of the connection unclear. Change-Id: I4f2b54bc086e8f4723a0357d983e3df2f85135ac Reviewed-by: Thiago Macieira --- src/corelib/kernel/qapplicationstatic.h | 3 ++- src/corelib/thread/qthread.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qapplicationstatic.h b/src/corelib/kernel/qapplicationstatic.h index 1eadeb20e2..f2f0911856 100644 --- a/src/corelib/kernel/qapplicationstatic.h +++ b/src/corelib/kernel/qapplicationstatic.h @@ -50,7 +50,8 @@ template struct ApplicationHolder QMutexLocker locker(&mutex); if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) { QAS::innerFunction(&storage); - QObject::connect(QCoreApplication::instance(), &QObject::destroyed, reset); + const auto *app = QCoreApplication::instance(); + QObject::connect(app, &QObject::destroyed, app, reset, Qt::DirectConnection); guard.storeRelease(QtGlobalStatic::Initialized); } return realPointer(); diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 9f00bf407d..61369420d1 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -1245,7 +1245,9 @@ QDaemonThread::QDaemonThread(QObject *parent) { // QThread::started() is emitted from the thread we start connect(this, &QThread::started, - [](){ QThreadData::current()->requiresCoreApplication = false; }); + this, + [](){ QThreadData::current()->requiresCoreApplication = false; }, + Qt::DirectConnection); } QDaemonThread::~QDaemonThread()