summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qloggingregistry.cpp10
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp8
2 files changed, 18 insertions, 0 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp
index b5f8e30b80..cd97268d71 100644
--- a/src/corelib/io/qloggingregistry.cpp
+++ b/src/corelib/io/qloggingregistry.cpp
@@ -44,6 +44,7 @@
#include <QtCore/qstandardpaths.h>
#include <QtCore/qtextstream.h>
#include <QtCore/qdir.h>
+#include <QtCore/qcoreapplication.h>
// We can't use the default macros because this would lead to recursion.
// Instead let's define our own one that unconditionally logs...
@@ -255,6 +256,15 @@ void QLoggingSettingsParser::parseNextLine(QStringRef line)
QLoggingRegistry::QLoggingRegistry()
: categoryFilter(defaultCategoryFilter)
{
+#if defined(Q_OS_ANDROID)
+ // Unless QCoreApplication has been constructed we can't be sure that
+ // we are on Qt's main thread. If we did allow logging here, we would
+ // potentially set Qt's main thread to Android's thread 0, which would
+ // confuse Qt later when running main().
+ if (!qApp)
+ return;
+#endif
+
initializeRules(); // Init on first use
}
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 12c2669f36..c8b130bbb9 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -776,6 +776,14 @@ void QCoreApplicationPrivate::init()
if (!coreappdata()->applicationVersionSet)
coreappdata()->applicationVersion = appVersion();
+#if defined(Q_OS_ANDROID)
+ // We've deferred initializing the logging registry due to not being
+ // able to guarantee that logging happened on the same thread as the
+ // Qt main thread, but now that the Qt main thread is set up, we can
+ // enable categorized logging.
+ QLoggingRegistry::instance()->initializeRules();
+#endif
+
#if QT_CONFIG(library)
// Reset the lib paths, so that they will be recomputed, taking the availability of argv[0]
// into account. If necessary, recompute right away and replay the manual changes on top of the