path: root/src/corelib/thread
diff options
authorEskil Abrahamsen Blomfeldt <>2014-01-13 14:19:49 +0100
committerThe Qt Project <>2014-01-16 15:41:21 +0100
commit894ce8aaab8d3319a704deb73cb5109d092df0aa (patch)
treee31abf7ddf41be853631958c12b13560d7e223e3 /src/corelib/thread
parentaa7ec3cdf5d423b7abb7d0bb5ff7772602d41962 (diff)
Android: Don't register main thread on loading library
When building with debug, all SLOT or SIGNAL macros will expand to a function call, and then function will call QThreadData::current(), which will set QCoreApplication::theMainThread if it has not already been done. Since Qt Widgets has these macros in the static initialization of the library, we would register the Android main thread as the main thread of Qt, which would mean that the actual application object was created on a different thread than the main thread. This caused warnings to appear, and also triggered a race condition which caused widget applications to sometimes show a black screen instead of content on startup when run with the OpenGL plugin. Task-number: QTBUG-35048 Change-Id: Ie8979f5e7cd5662f8d7dd276de9f94f27cc120b5 Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/corelib/thread')
3 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 8429e41433..fce84e881b 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -223,7 +223,7 @@ public:
QThreadData(int initialRefCount = 1);
- static QThreadData *current();
+ static QThreadData *current(bool createIfNecessary = true);
static void clearCurrentThreadData();
static QThreadData *get2(QThread *thread)
{ Q_ASSERT_X(thread != 0, "QThread", "internal error"); return thread->d_func()->data; }
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 15558cb148..b838cb4b28 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -215,10 +215,10 @@ void QThreadData::clearCurrentThreadData()
-QThreadData *QThreadData::current()
+QThreadData *QThreadData::current(bool createIfNecessary)
QThreadData *data = get_thread_data();
- if (!data) {
+ if (!data && createIfNecessary) {
data = new QThreadData;
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index 037343c996..865b1e6af5 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -101,11 +101,11 @@ void QThreadData::clearCurrentThreadData()
TlsSetValue(qt_current_thread_data_tls_index, 0);
-QThreadData *QThreadData::current()
+QThreadData *QThreadData::current(bool createIfNecessary)
QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index));
- if (!threadData) {
+ if (!threadData && createIfNecessary) {
threadData = new QThreadData;
// This needs to be called prior to new AdoptedThread() to
// avoid recursion.