diff options
author | Sergio Martins <sergio.martins@kdab.com> | 2018-03-02 18:36:20 +0000 |
---|---|---|
committer | Sérgio Martins <sergio.martins@kdab.com> | 2018-03-08 22:36:49 +0000 |
commit | c082d84d5d7fdbfb64de18f06a8ddbc77f2e6de4 (patch) | |
tree | 1d881e4d7610fb0f5d94ac6b8f586886c45db46b /tests/auto | |
parent | e5a6e9bb80fb2427228f70488b8839b4aa0b4261 (diff) |
Fix QLabel crash if buddy's lifetime is too short
If buddy is deleted then QLabel will still try to deliver the
shortcut event to it, in QLabel::event(), and cras.
Besides connecting to destroyed() which alone fixes the crash,
also hardened it and guarded against dereferencing null buddy,
in the unlikely event of someone adding features to QLabel.
The second part is suitable for backporting to the LTS branches.
Task-Id: QTBUG-66841
Change-Id: Ib6a36a9f99cee31afe1f88eb77f5b6cafb8b1086
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index 500ec2e1fa..84071962bc 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -178,9 +178,11 @@ void tst_QLabel::setBuddy() test_label= new QLabel( test_box ); test_label->setText( "&Test with a buddy" ); QWidget *test_edit = new QLineEdit( test_box ); + QWidget *test_edit2 = new QLineEdit( test_box ); QVBoxLayout *layout = new QVBoxLayout(test_box); layout->addWidget(test_label); layout->addWidget(test_edit); + layout->addWidget(test_edit2); test_box->show(); qApp->setActiveWindow(test_box); QVERIFY(test_box->isActiveWindow()); @@ -190,6 +192,16 @@ void tst_QLabel::setBuddy() QVERIFY( !test_edit->hasFocus() ); QTest::keyClick( test_box, 't', Qt::AltModifier ); QVERIFY( test_edit->hasFocus() ); + + // Setting a new buddy should disconnect the old one's destroyed() signal + test_label->setBuddy(test_edit2); + delete test_edit; + QCOMPARE(test_label->buddy(), test_edit2); + + // And deleting our own buddy should disconnect and not crash + delete test_edit2; + QTest::keyClick(test_box, 't', Qt::AltModifier ); + delete test_box; } #endif |