summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-01 12:31:11 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-01 15:01:52 +0000
commit84535d5136304c9b35a261e66743300680a35e8f (patch)
tree35cf250c77e6684d9c546e0af5f4cdcd79904e84 /tests
parentcb10cf1e437a4176b7f1f0e6150b77af5ae9ff43 (diff)
QFontCache: don't start cleanup timer if we are not in the main thread
We can only start timers in threads started via QThread, and even then we cannot assume that the thread runs an event loop. So only start the timer when we are in the main thread. Add a test that verifies that we don't get the warning message. Change-Id: I40d7d9ff115720f9ecd3eedaebbade2643daf843 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 132d6d012701ce00a4ff82eae5b14e560632e893) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qfontcache/tst_qfontcache.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
index 3a7eebdc64..17d199210d 100644
--- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
+++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
@@ -47,6 +47,7 @@ private slots:
void engineData();
void engineDataFamilies_data();
void engineDataFamilies();
+ void threadedAccess();
void clear();
};
@@ -227,5 +228,51 @@ for (int i = 0; i < leakedEngines.size(); ++i) qWarning() << i << leakedEngines.
#endif
}
+struct MessageHandler
+{
+ MessageHandler()
+ {
+ oldMessageHandler = qInstallMessageHandler(myMessageHandler);
+ messages.clear();
+ }
+ ~MessageHandler()
+ {
+ qInstallMessageHandler(oldMessageHandler);
+ }
+
+ inline static bool receivedMessage = false;
+ inline static QtMessageHandler oldMessageHandler = nullptr;
+ inline static QStringList messages;
+ static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &text)
+ {
+ if (!text.startsWith("Populating font family aliases took")) {
+ receivedMessage = true;
+ messages += text;
+ }
+ if (oldMessageHandler)
+ oldMessageHandler(type, context, text);
+ }
+};
+
+
+void tst_QFontCache::threadedAccess()
+{
+ MessageHandler messageHandler;
+ auto lambda = []{
+ for (const auto &family : QFontDatabase::families()) {
+ QFont font(family);
+ QFontMetrics fontMetrics(font);
+ fontMetrics.height();
+ }
+ };
+ auto *qThread = QThread::create(lambda);
+ qThread->start();
+ qThread->wait();
+
+ std::thread stdThread(lambda);
+ stdThread.join();
+ QVERIFY2(!messageHandler.receivedMessage, qPrintable(messageHandler.messages.join('\n')));
+}
+
QTEST_MAIN(tst_QFontCache)
#include "tst_qfontcache.moc"