diff options
author | Robin Burchell <robin.burchell@collabora.co.uk> | 2011-05-05 08:49:59 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-05-05 08:49:59 (GMT) |
commit | 124ec3200f8453142717fcfe7a4aa0a55164aaa6 (patch) | |
tree | 4748b83c5941cd5c839f8e3423b384015e8ffe2f /tests | |
parent | 4237c59dba78d80be165ae8dd1691abfc61503b1 (diff) | |
download | Qt-124ec3200f8453142717fcfe7a4aa0a55164aaa6.zip Qt-124ec3200f8453142717fcfe7a4aa0a55164aaa6.tar.gz Qt-124ec3200f8453142717fcfe7a4aa0a55164aaa6.tar.bz2 |
Ensure that QDateTimeEdit::calendarWidget() will always return a valid widget.
This case may be triggered in the (admittedly slightly abnormal) case where a
user wishes to embed the calendar widget in a layout or, for whatever reason, do
something else that will change its ownership.
We work around this by detecting when it is deleted and recreating the widget.
This will also have a positive side effect if setCalendarWidget() is called with
a widget which is then subsequently deleted, returning the default widget
instead of a pointer to (now deleted) memory.
Reviewed-by: Denis Dzyubenko
Merge-request: 2568
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qdatetimeedit/tst_qdatetimeedit.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/qdatetimeedit/tst_qdatetimeedit.cpp index c8c3b90..9d0c5f7 100644 --- a/tests/auto/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/qdatetimeedit/tst_qdatetimeedit.cpp @@ -275,6 +275,8 @@ private slots: void focusNextPrevChild(); void taskQTBUG_12384_timeSpecShowTimeOnly(); + + void deleteCalendarWidget(); private: EditorDateEdit* testWidget; @@ -3438,5 +3440,26 @@ void tst_QDateTimeEdit::taskQTBUG_12384_timeSpecShowTimeOnly() QCOMPARE(edit.time(), time.time()); } +void tst_QDateTimeEdit::deleteCalendarWidget() +{ + { + // setup + QCalendarWidget *cw = 0; + QDateEdit edit; + QVERIFY(!edit.calendarWidget()); + edit.setCalendarPopup(true); + QVERIFY(edit.calendarWidget()); + edit.calendarWidget()->setObjectName("cw1");; + + // delete + cw = edit.calendarWidget(); + delete cw; + + // it should create a new widget + QVERIFY(edit.calendarWidget()); + QVERIFY(edit.calendarWidget()->objectName() != "cw1"); + } +} + QTEST_MAIN(tst_QDateTimeEdit) #include "tst_qdatetimeedit.moc" |