Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML DateTimeAxis show UTC time
QtWS25 Last Chance

QML DateTimeAxis show UTC time

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 544 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    logari84
    wrote on last edited by
    #1

    Dear all,

    I have noticed that 'min' and 'max' properties of DateTimeAxis, are displayed based on the locale settings, meaning the time shown in the time axis is in the current locale. Is it possible to show the datetime on Axis, in UTC?

    Follows an example according to my use case.

    This is the QML part where the DateTimeAxis is defined. 'min' property is attached to the 'metisChart.minTime' which is member of a custom cpp class.

    DateTimeAxis {
      id: axisX
      min: metisChart.minTime
      max: metisChart.maxTime
      gridVisible: true
      format: metisChart.xAxisLabel ? metisChart.xAxisLabel : "hh:mm"
      titleText: "Timestamp"
      tickCount: 6
    
      onMinChanged: {
        console.log("QML min: " + axisX.min.toUTCString())
      }
    }
    

    QML output using .toUTCString():

    QML min: Thu Dec 30 12:53:41 2021 GMT
    

    This is the CPP part where the new datetime value is set and the corresponding signal is emitted. Using qInfo() the time is printed to show that it is correctly displayed in UTC.

    void ChartLiveData::setMinTime(QDateTime time)
    {
      if(m_minTime == time)
        return;
    
      m_minTime = time;
      qInfo() << "CPP minTime " << m_minTime.toUTC();
      emit minTimeChanged(m_minTime);
    }
    

    CPP output:

    CPP minTime  QDateTime(2021-12-30 12:53:41.289 UTC Qt::UTC)
    

    As shown in the image bellow, the time axis is showing the datetime shifted by +2 hours (min is 14:53), which is expected according to my TimeZone.
    DateTime_issue.png

    Is there a way to set the Axis display format in UTC? I haven't found any useful information on the documentation. The only thing that is mentioned is to format based on a specific locale, which sounds like a very bad practice in my case.

    Thank you in advance.

    Kind regards

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved