diff options
author | Zhang Yu <zhangyub@uniontech.com> | 2021-06-15 21:05:41 +0800 |
---|---|---|
committer | Zhang Yu <zhangyub@uniontech.com> | 2021-06-18 05:34:52 +0000 |
commit | e9cdcc7cb314586aec76b8b9979435f0af963443 (patch) | |
tree | d1f31e33e2992b47dda8e25531c58e998cb7d72a /tests/auto/widgets | |
parent | 0c2ca26cd9583092f3ade7b18bc2423336a6202b (diff) |
Fix recursion crash when calling setStyleSheet with `qproperty-styleSheet`
When calling `setStyleSheet` with property `qproperty-styleSheet`,
`QStyleSheetStyle::polish` will call`QStyleSheetStyle::setProperties`, and then`QStyleSheetStyle::setProperties` goes on to call `setProperty`.Because there is property `qproperty-styleSheet`, it will update stylesheet by calling QStyleSheetStyle::polish`.
This causes the recursive call to crash.
Fixes: QTBUG-94448
Pick-to: 5.15 6.2
Change-Id: I79c51192a939b0b62e5b1d0dcc90d38f79e28222
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 6c4c7d577b..27500173c8 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -92,6 +92,7 @@ private slots: void layoutSpacing(); #endif void qproperty(); + void qproperty_styleSheet(); void palettePropagation_data(); void palettePropagation(); void fontPropagation_data(); @@ -672,6 +673,23 @@ void tst_QStyleSheetStyle::qproperty() QCOMPARE(pb.isChecked(), false); } +void tst_QStyleSheetStyle::qproperty_styleSheet() +{ + QWidget w; + auto checkBox = new QCheckBox("check", &w); + QString sheet = R"(QCheckBox { qproperty-styleSheet: "QCheckBox { qproperty-text: foobar; }"; })"; + + QVERIFY(w.property("styleSheet").toString().isEmpty()); + + w.setStyleSheet(sheet); + QCOMPARE(checkBox->text(), "check"); + + //recursion crash + w.ensurePolished(); + QCOMPARE(w.property("styleSheet").toString(), sheet); + QCOMPARE(checkBox->text(), "foobar"); +} + namespace ns { class PushButton1 : public QPushButton { Q_OBJECT |