From 607c5a90c5c575be6ef7755d7e48e37dded2f74e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 3 Aug 2022 14:11:18 +0200 Subject: [PATCH] Fix initialization of QDateEdit and QTimeEdit Since 6.3 these use Qt::UTC as time-spec but I neglected to take that into account in QDateTimeEditPrivate::init()'s construction of a QDateTime from the QDate or QTime. This amends commit c00ee2f31013e99c79b820a0db57003c110a5510. Fixes: QTBUG-105322 Pick-to: 6.3 6.4 Change-Id: I11dec9808a54cf7da401b1734a9a2812f5fd2e63 Reviewed-by: Thiago Macieira --- src/widgets/widgets/qdatetimeedit.cpp | 4 ++-- .../auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 3c9d166dee..897e0dce06 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -2480,7 +2480,7 @@ void QDateTimeEditPrivate::init(const QVariant &var) Q_Q(QDateTimeEdit); switch (var.userType()) { case QMetaType::QDate: - value = var.toDate().startOfDay(); + value = var.toDate().startOfDay(spec); updateTimeSpec(); q->setDisplayFormat(defaultDateFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale @@ -2494,7 +2494,7 @@ void QDateTimeEditPrivate::init(const QVariant &var) q->setDisplayFormat("dd/MM/yyyy hh:mm:ss"_L1); break; case QMetaType::QTime: - value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime()); + value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime(), spec); updateTimeSpec(); q->setDisplayFormat(defaultTimeFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index 1328e11f03..fe20de9d86 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -506,7 +506,6 @@ void tst_QDateTimeEdit::constructor_qdate() { QDateEdit dte(parameter); dte.show(); - QEXPECT_FAIL("", "QTBUG-105322: constructors use wrong spec", Continue); if (QByteArrayView(QTest::currentDataTag()) == "invalid") QCOMPARE(dte.date(), QDate(2000, 1, 1)); else @@ -546,7 +545,6 @@ void tst_QDateTimeEdit::constructor_qtime() { QTimeEdit dte(parameter); dte.show(); - QEXPECT_FAIL("", "QTBUG-105322: constructors use wrong spec", Abort); if (QByteArrayView(QTest::currentDataTag()) == "invalid") QCOMPARE(dte.time(), QTime(0, 0)); else