From 9a131b59ee561e300fb6078886a85dd7b3c53599 Mon Sep 17 00:00:00 2001 From: Zhang Hao Date: Wed, 10 Nov 2021 17:29:21 +0800 Subject: [PATCH] QFontComboBox don't response qApp fontDatabaseChanged() If QFontComboBox is instantiated in the form of new and call QFontDatabase::addApplicationFont, QFontComboBoxPrivate::_q_updateModel() will be called when the program exits, at this time qApp will crash. Fix this by when program exiting, QFontComboBoxPrivate don't need call _q_updateModel(). Fixes: QTBUG-98099 Done-With: Konstantin Ritt Pick-to: 5.15 6.2 Change-Id: I3df3d19c3d1971288d60f2eef386262befbf396b Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/widgets/widgets/qfontcombobox.cpp | 4 ++++ .../widgets/qfontcombobox/tst_qfontcombobox.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/widgets/widgets/qfontcombobox.cpp b/src/widgets/widgets/qfontcombobox.cpp index 60a1f06764..a282f4ef3b 100644 --- a/src/widgets/widgets/qfontcombobox.cpp +++ b/src/widgets/widgets/qfontcombobox.cpp @@ -311,6 +311,10 @@ public: void QFontComboBoxPrivate::_q_updateModel() { Q_Q(QFontComboBox); + + if (QCoreApplication::closingDown()) + return; + const int scalableMask = (QFontComboBox::ScalableFonts | QFontComboBox::NonScalableFonts); const int spacingMask = (QFontComboBox::ProportionalFonts | QFontComboBox::MonospacedFonts); diff --git a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp index 3b5a9387ab..3b7965402e 100644 --- a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp @@ -260,15 +260,18 @@ void tst_QFontComboBox::writingSystem() // protected void currentFontChanged(QFont const& f) void tst_QFontComboBox::currentFontChanged() { - SubQFontComboBox box; - QSignalSpy spy0(&box, SIGNAL(currentFontChanged(QFont))); + // The absence of this file does not affect the test results + QFontDatabase::addApplicationFont("ArianaVioleta-dz2K.ttf"); - if (box.model()->rowCount() > 2) { - QTest::keyPress(&box, Qt::Key_Down); + SubQFontComboBox *box = new SubQFontComboBox; + QSignalSpy spy0(box, SIGNAL(currentFontChanged(QFont))); + + if (box->model()->rowCount() > 2) { + QTest::keyPress(box, Qt::Key_Down); QCOMPARE(spy0.count(), 1); QFont f( "Sans Serif" ); - box.setCurrentFont(f); + box->setCurrentFont(f); QCOMPARE(spy0.count(), 2); } else qWarning("Not enough fonts installed on test system. Consider adding some");