diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 4afe22e8a56..0f1de6b97cd 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -536,14 +536,6 @@ QThread *QCoreApplicationPrivate::mainThread() return theMainThread.loadRelaxed(); } -bool QCoreApplicationPrivate::threadRequiresCoreApplication() -{ - QThreadData *data = QThreadData::current(false); - if (!data) - return true; // default setting - return data->requiresCoreApplication; -} - void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver) { QThread *currentThread = QThread::currentThread(); @@ -1107,7 +1099,13 @@ void QCoreApplication::setQuitLockEnabled(bool enabled) */ bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event) { - bool selfRequired = QCoreApplicationPrivate::threadRequiresCoreApplication(); + // Qt enforces the rule that events can only be sent to objects in + // the current thread, so receiver->d_func()->threadData is + // equivalent to QThreadData::current(), just without the function + // call overhead. + QObjectPrivate *d = receiver->d_func(); + QThreadData *threadData = d->threadData.loadAcquire(); + bool selfRequired = threadData->requiresCoreApplication; if (selfRequired && !qApp) return false; @@ -1119,12 +1117,6 @@ bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event) return result; } - // Qt enforces the rule that events can only be sent to objects in - // the current thread, so receiver->d_func()->threadData is - // equivalent to QThreadData::current(), just without the function - // call overhead. - QObjectPrivate *d = receiver->d_func(); - QThreadData *threadData = d->threadData.loadAcquire(); QScopedScopeLevelCounter scopeLevelCounter(threadData); if (!selfRequired) return doNotify(receiver, event); diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index 0ad6eb6640e..48783626bdc 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -113,7 +113,6 @@ public: static QBasicAtomicPointer theMainThread; static QBasicAtomicPointer theMainThreadId; static QThread *mainThread(); - static bool threadRequiresCoreApplication(); static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data); diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 2d401e7a425..500b67ea6ae 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -67,10 +67,11 @@ QEventLoop::QEventLoop(QObject *parent) : QObject(*new QEventLoopPrivate, parent) { Q_D(QEventLoop); - if (!QCoreApplication::instance() && QCoreApplicationPrivate::threadRequiresCoreApplication()) { - qWarning("QEventLoop: Cannot be used without QApplication"); + QThreadData *threadData = d->threadData.loadRelaxed(); + if (!QCoreApplication::instance() && threadData->requiresCoreApplication) { + qWarning("QEventLoop: Cannot be used without QCoreApplication"); } else { - d->threadData.loadRelaxed()->ensureEventDispatcher(); + threadData->ensureEventDispatcher(); } } diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index bc6710d1981..297c3f45ac9 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3262,8 +3262,9 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) Q_TRACE_EXIT(QApplication_notify_exit, consumed, filtered); // send to all application event filters - if (threadRequiresCoreApplication() - && receiver->d_func()->threadData.loadRelaxed()->thread.loadAcquire() == mainThread() + QThreadData *threadData = receiver->d_func()->threadData.loadRelaxed(); + if (threadData->requiresCoreApplication + && threadData->thread.loadAcquire() == mainThread() && sendThroughApplicationEventFilters(receiver, e)) { filtered = true; return filtered;