aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrolstestutils/controlstestutils.cpp
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2025-06-19 13:56:17 +0800
committerMitch Curtis <[email protected]>2025-06-30 13:31:50 +0800
commit57325020f65665d91e63dc300d674a8e8dc411f1 (patch)
tree9cf538f41d7b47fb33aa4508353016690bd9b155 /src/quickcontrolstestutils/controlstestutils.cpp
parentaa1d3e416edd092f3dc8f8a20f15bd92baa93485 (diff)
MonthGrid: fix dates being incorrect for certain timezonesHEADdev
When a QDate is passed to QML, it becomes to a JavaScript Date. As Dates are stored in local time, the QDates we were passing to QML had the potential to be one day off in certain timezones. For example: 00:00 UTC converted to UTC-8 is 20:00 the day before. Fix this by storing and providing dates as QDateTime so that we can give it a time of day that can't possibly result in a different day when converted to local time. It's fine to change the C++ API since it's private, and nothing will change for the type that users see, since they always get a Date. Add a SystemEnvironment singleton to QQuickControlsTestUtils (Qt.test.controls) to allow reading and writing environment variables from QML. Fixes: QTBUG-72208 Pick-to: 6.8 6.9 6.10 Change-Id: Idb4ab26568d8f1eddd5ab4cebe691e38173d02a9 Reviewed-by: Ulf Hermann <[email protected]>
Diffstat (limited to 'src/quickcontrolstestutils/controlstestutils.cpp')
-rw-r--r--src/quickcontrolstestutils/controlstestutils.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/quickcontrolstestutils/controlstestutils.cpp b/src/quickcontrolstestutils/controlstestutils.cpp
index fb88d00d29..f6b02abbe3 100644
--- a/src/quickcontrolstestutils/controlstestutils.cpp
+++ b/src/quickcontrolstestutils/controlstestutils.cpp
@@ -186,6 +186,21 @@ QString QQuickControlsTestUtils::StyleInfo::styleName() const
return QQuickStyle::name();
}
+/*!
+ It's recommended to use try-finally (see tst_monthgrid.qml for an example)
+ or init/initTestCase and cleanup/cleanupTestCase if setting environment
+ variables, in order to restore previous values.
+*/
+QString QQuickControlsTestUtils::SystemEnvironment::value(const QString &name)
+{
+ return QString::fromLocal8Bit(qgetenv(name.toLocal8Bit()));
+}
+
+bool QQuickControlsTestUtils::SystemEnvironment::setValue(const QString &name, const QString &value)
+{
+ return qputenv(name.toLocal8Bit(), value.toLocal8Bit());
+}
+
QString QQuickControlsTestUtils::visualFocusFailureMessage(QQuickControl *control)
{
QString message;