From 3f32dcd1ddcbe04c77ccd83e2eaa566d7212e732 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 12 Jan 2022 10:47:19 +0100 Subject: [PATCH] Allow reading QObject::objectName from other threads again The new binding system made it impossible to read from non-owning threads, but we have code that did so with external locking. This patch makes it safe again, assuming all reads and writes are locked. This is left intentionally undocumented. Pick-to: 6.3 6.2 Task-number: QTBUG-99775 Change-Id: I845afa5d545ca0ac762ac369181b1497dac52195 Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qobject.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 523e952579a..eac5f33501b 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1245,6 +1245,10 @@ QObjectPrivate::Connection::~Connection() QString QObject::objectName() const { Q_D(const QObject); +#if QT_CONFIG(thread) + if (QThread::currentThreadId() != d->threadData.loadRelaxed()->threadId.loadRelaxed()) // Unsafe code path + return d->extraData ? d->extraData->objectName.valueBypassingBindings() : QString(); +#endif if (!d->extraData && QtPrivate::isAnyBindingEvaluating()) { QObjectPrivate *dd = const_cast(d); // extraData is mutable, so this should be safe