passing QDateTime into QML
-
Hi all -
I'm trying to pass a QDateTime object into QML, and I seem to be losing the time zone in the process.
QDateTime m_dateTimeForTimezone { QDateTime::currentDateTimeUtc().toTimeZone(m_timeZone) }; Q_PROPERTY(QDateTime dateTimeForTimezone READ dateTimeForTimezone WRITE setDateTimeForTimezone NOTIFY dateTimeForTimezoneChanged FINAL)
In my QML:
onClicked: { dateTime = clock.dateTimeForTimezone console.log("PrefsDateTime.qml: dateTime is " + dateTime) // shows the wrong time.
Evidently, this isn't a new issue: this description seems to be the same thing.
My question: are the proposed solutions in the SO thread really the best way to solve this, or is there a cleaner way to do it?
Thanks...
-
Not really a solution (more of a band-aid), but...I added properties to my clock for the parts of the date/time I needed:
int m_minutes; Q_PROPERTY(int minutes READ minutes WRITE setMinutes NOTIFY minutesChanged FINAL) int m_hours; Q_PROPERTY(int hours READ hours WRITE setHours NOTIFY hoursChanged FINAL)
and referenced them individually:
property int minutes: clock.minutes property int hours: clock.hours
Not a great fix, but it got me past the problem.
-
Not really a solution (more of a band-aid), but...I added properties to my clock for the parts of the date/time I needed:
int m_minutes; Q_PROPERTY(int minutes READ minutes WRITE setMinutes NOTIFY minutesChanged FINAL) int m_hours; Q_PROPERTY(int hours READ hours WRITE setHours NOTIFY hoursChanged FINAL)
and referenced them individually:
property int minutes: clock.minutes property int hours: clock.hours
Not a great fix, but it got me past the problem.
-
M mzimmers has marked this topic as solved on