tst_QCalendarWidget: fix memleak in showPrevNext()
QObject parents own their children, but not the other way around. So the parent-less QWidget *parent created on the heap was leaked. To fix, create it on the stack instead, but for that to work, it must be declared _before_ its eventual child, otherwise the parent would delete the child as a QObject child, followed by the compiler deleting the child as an automatic variable = double-delete. Amends ab536c3c71deaaa3b67ca87c47628355d9f348e8. Pick-to: 6.8 6.5 5.15 Change-Id: Ibccf229fc056665e3b854e1a94e1f4b5bf7a89e1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 3c7719f2c248a2710c75fa47e12759188abf673d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
4a16b18fb4
commit
2ec89d4908
@ -313,6 +313,7 @@ void tst_QCalendarWidget::showPrevNext()
|
|||||||
void tst_QCalendarWidget::firstDayOfWeek()
|
void tst_QCalendarWidget::firstDayOfWeek()
|
||||||
{
|
{
|
||||||
// Ensure the default locale is chosen.
|
// Ensure the default locale is chosen.
|
||||||
|
QWidget parent;
|
||||||
QCalendarWidget calendar;
|
QCalendarWidget calendar;
|
||||||
QLocale locale;
|
QLocale locale;
|
||||||
QCOMPARE(calendar.firstDayOfWeek(), locale.firstDayOfWeek());
|
QCOMPARE(calendar.firstDayOfWeek(), locale.firstDayOfWeek());
|
||||||
@ -335,17 +336,16 @@ void tst_QCalendarWidget::firstDayOfWeek()
|
|||||||
QCOMPARE(calendar.firstDayOfWeek(), frenchLocale.firstDayOfWeek());
|
QCOMPARE(calendar.firstDayOfWeek(), frenchLocale.firstDayOfWeek());
|
||||||
|
|
||||||
// Ensure that setting the locale of parent widget has an effect.
|
// Ensure that setting the locale of parent widget has an effect.
|
||||||
QWidget* parent = new QWidget;
|
calendar.setParent(&parent);
|
||||||
calendar.setParent(parent);
|
|
||||||
QLocale hausaLocale(QLocale::Hausa);
|
QLocale hausaLocale(QLocale::Hausa);
|
||||||
parent->setLocale(hausaLocale);
|
parent.setLocale(hausaLocale);
|
||||||
QCOMPARE(calendar.firstDayOfWeek(), hausaLocale.firstDayOfWeek());
|
QCOMPARE(calendar.firstDayOfWeek(), hausaLocale.firstDayOfWeek());
|
||||||
|
|
||||||
// Ensure that widget-specific locale takes precedence over parent.
|
// Ensure that widget-specific locale takes precedence over parent.
|
||||||
calendar.setLocale(germanLocale);
|
calendar.setLocale(germanLocale);
|
||||||
// Sanity check...
|
// Sanity check...
|
||||||
QCOMPARE(calendar.locale(), germanLocale);
|
QCOMPARE(calendar.locale(), germanLocale);
|
||||||
QCOMPARE(parent->locale(), hausaLocale);
|
QCOMPARE(parent.locale(), hausaLocale);
|
||||||
QCOMPARE(calendar.firstDayOfWeek(), germanLocale.firstDayOfWeek());
|
QCOMPARE(calendar.firstDayOfWeek(), germanLocale.firstDayOfWeek());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user