Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The constructors QQmlApplicationEngine and QSettings spoil the time zone (daylight)
QtWS25 Last Chance

The constructors QQmlApplicationEngine and QSettings spoil the time zone (daylight)

Scheduled Pinned Locked Moved Unsolved General and Desktop
daylighttimezonebug
8 Posts 3 Posters 1.6k 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.
  • X Offline
    X Offline
    xintrea
    wrote on 18 May 2018, 13:59 last edited by xintrea
    #1

    I came across the strange behavior of the QQmlApplicationEngine constructor. The minimum code is main.cpp:

    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        qDebug() << "1ST timezone=" << timezone << " daylight=" << daylight;
        tzset();
        qDebug() << "2ND timezone=" << timezone << " daylight=" << daylight;
    
        QQmlApplicationEngine engine;
    
        qDebug() << "3ND timezone=" << timezone << " daylight=" << daylight;
    
        return app.exec();
    }
    

    Result of work:

    1ST timezone= 0  daylight= 0
    2ND timezone= -10800  daylight= 1
    3ND timezone= -10800  daylight= 0
    

    That is, after the QQmlApplicationEngine constructor is triggered, daylight spoils (switch to zero).

    I was surprised, but it's necessary to work and therefore I tried to get around this case like this:

    long saveTimezone=timezone;
    int saveDaylight=daylight;
    
    QQmlApplicationEngine engine;
    
    timezone=saveTimezone;
    daylight=saveDaylight;
    

    It worked, but in the project I still found another one place in which the same behavior, after the QSettings constructor (but already in the heap). Looks like that:

    qDebug() << "CURRENT timezone=" << timezone << " daylight=" << daylight;
    QSettings *config=new QSettings(fileName, QSettings::IniFormat, this);
    qDebug() << "CURRENT timezone=" << timezone << " daylight=" << daylight;
    
    CURRENT timezone= -10800  daylight= 1
    CURRENT timezone= -10800  daylight= 0
    

    But in a minimal code, I could not repeat this.

    Where else the variable daylight can spoil, I do not know, but I do not rule out such probabilities. The problem is that my project uses a legacy library that works with daylight, and because of these problems it gives the wrong time.

    Questions: what kind of problem is this, why do some Qt classes spoil daylight, how is this thing guaranteed to work around?

    PS: The project file that would quickly compile a minimal example (only the project file and main.cpp will be required):

    time.pro

    CONFIG+=c++11
    CONFIG+=qml_debug
    QT+=gui
    QT+=core
    QT+=quick
    QT+=widgets
    SOURCES += main.cpp
    DEFINES += QT_DEPRECATED_WARNINGS
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 May 2018, 20:24 last edited by
      #2

      Hi,

      Intriguing !

      What version of Qt are you using ?
      On what platform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      X 1 Reply Last reply 19 May 2018, 04:42
      0
      • S SGaist
        18 May 2018, 20:24

        Hi,

        Intriguing !

        What version of Qt are you using ?
        On what platform ?

        X Offline
        X Offline
        xintrea
        wrote on 19 May 2018, 04:42 last edited by
        #3

        @SGaist
        Debian Linux Stable 64 bit, Qt 5.10.1 by official site.

        K 1 Reply Last reply 19 May 2018, 19:17
        0
        • X xintrea
          19 May 2018, 04:42

          @SGaist
          Debian Linux Stable 64 bit, Qt 5.10.1 by official site.

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 19 May 2018, 19:17 last edited by
          #4

          @xintrea said in The constructors QQmlApplicationEngine and QSettings spoil the time zone (daylight):

          Qt 5.10.1 by official site

          You mean downloaded from qt.io, correct? Because debian doesn't provide that in stable, but the current Qt version for the testing flavor is exactly 5.10.1.

          Read and abide by the Qt Code of Conduct

          X 1 Reply Last reply 20 May 2018, 15:18
          0
          • K kshegunov
            19 May 2018, 19:17

            @xintrea said in The constructors QQmlApplicationEngine and QSettings spoil the time zone (daylight):

            Qt 5.10.1 by official site

            You mean downloaded from qt.io, correct? Because debian doesn't provide that in stable, but the current Qt version for the testing flavor is exactly 5.10.1.

            X Offline
            X Offline
            xintrea
            wrote on 20 May 2018, 15:18 last edited by
            #5

            @kshegunov
            Yes. I use Debian Stable 9 (64-bit) with all updates:

            > lsb_release -a
            No LSB modules are available.
            Distributor ID: Debian
            Description:    Debian GNU/Linux 9.3 (stretch)
            Release:        9.3
            Codename:       stretch
            

            I get Qt from qt.io as file qt-opensource-linux-x64-5.10.1.run.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 20 May 2018, 19:54 last edited by
              #6

              Do you get the same behaviour if you use Debian's provided version of Qt ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              X 2 Replies Last reply 25 May 2018, 15:13
              0
              • S SGaist
                20 May 2018, 19:54

                Do you get the same behaviour if you use Debian's provided version of Qt ?

                X Offline
                X Offline
                xintrea
                wrote on 25 May 2018, 15:13 last edited by
                #7

                @SGaist

                I not experiment with Qt version.

                But i debug this situation. I set watchpoint to system global variable daylight. This is stack if run constructor QQmlApplicationEngine:

                (gdb) where
                #0  update_vars () at tzset.c:156
                #1  0x00007ffff3c8a569 in __tzset_parse_tz (tz=<optimized out>) at tzset.c:391
                #2  0x00007ffff3c8c27b in __tzfile_compute (timer=<optimized out>, use_localtime=use_localtime@entry=1, 
                    leap_correct=leap_correct@entry=0x7fffffffd938, leap_hit=leap_hit@entry=0x7fffffffd934, tp=tp@entry=0x7fffffffd980)
                    at tzfile.c:691
                #3  0x00007ffff3c8ac44 in __tz_convert (timer=0x7fffffffd978, use_localtime=1, tp=0x7fffffffd980) at tzset.c:624
                #4  0x00007ffff608230a in ?? () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                #5  0x00007ffff608afab in ?? () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                #6  0x00007ffff60692db in QV4::ExecutionEngine::ExecutionEngine(QV4::EvalISelFactory*) ()
                   from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                #7  0x00007ffff61c949a in QV8Engine::QV8Engine(QJSEngine*) () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                #8  0x00007ffff5fffb14 in QJSEngine::QJSEngine(QJSEnginePrivate&, QObject*) ()
                   from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                #9  0x00007ffff6127969 in QQmlEngine::QQmlEngine(QQmlEnginePrivate&, QObject*) ()
                   from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                #10 0x00007ffff61b44e0 in QQmlApplicationEngine::QQmlApplicationEngine(QObject*) ()
                   from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Qml.so.5
                

                And this is stack if run constructor QSettings:

                (gdb) where
                #0  update_vars () at tzset.c:156
                #1  0x00007ffff3c8a569 in __tzset_parse_tz (tz=<optimized out>) at tzset.c:391
                #2  0x00007ffff3c8c27b in __tzfile_compute (timer=<optimized out>, use_localtime=use_localtime@entry=1, 
                    leap_correct=leap_correct@entry=0x7fffffffd3f8, leap_hit=leap_hit@entry=0x7fffffffd3f4, tp=tp@entry=0x7fffffffd4a0)
                    at tzfile.c:691
                #3  0x00007ffff3c8ac44 in __tz_convert (timer=0x7fffffffd498, use_localtime=1, tp=0x7fffffffd4a0) at tzset.c:624
                #4  0x00007ffff4dc8709 in QDateTime::setMSecsSinceEpoch(long long) () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #5  0x00007ffff4dcab4d in QDateTime::fromMSecsSinceEpoch(long long, Qt::TimeSpec, int) ()
                   from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #6  0x00007ffff4dcb00d in QDateTime::fromMSecsSinceEpoch(long long) () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #7  0x00007ffff4e87226 in QFileInfo::fileTime(QFileDevice::FileTime) const ()
                   from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #8  0x00007ffff4e8732e in QFileInfo::lastModified() const () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #9  0x00007ffff4ec90e1 in ?? () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #10 0x00007ffff4ec98cd in ?? () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #11 0x00007ffff4eca4b4 in ?? () from /opt/qt_5_10_1/5.10.1/gcc_64/lib/libQt5Core.so.5
                #12 0x00007ffff4eca57f in QSettings::QSettings(QString const&, QSettings::Format, QObject*)
                

                Really, QQmlApplicationEngine and QSettings is change timezone and, therefore, daylight.

                1 Reply Last reply
                0
                • S SGaist
                  20 May 2018, 19:54

                  Do you get the same behaviour if you use Debian's provided version of Qt ?

                  X Offline
                  X Offline
                  xintrea
                  wrote on 25 May 2018, 16:03 last edited by
                  #8

                  @SGaist

                  And function update_vars() is:

                  151 static void                                                                                                              
                  152 internal_function                                                                                                        
                  153 update_vars (void)                                                                                                       
                  154 {                                                                                                                        
                  155   __daylight = tz_rules[0].offset != tz_rules[1].offset;                                                                 
                  156   __timezone = -tz_rules[0].offset;                                                                                      
                  157   __tzname[0] = (char *) tz_rules[0].name;                                                                               
                  158   __tzname[1] = (char *) tz_rules[1].name;                                                                               
                  159                                                                                                                          
                  160   /* Keep __tzname_cur_max up to date.  */                                                                               
                  161   size_t len0 = strlen (__tzname[0]);                                                                                    
                  162   size_t len1 = strlen (__tzname[1]);                                                                                    
                  163   if (len0 > __tzname_cur_max)                                                                                           
                  164     __tzname_cur_max = len0;                                                                                             
                  165   if (len1 > __tzname_cur_max)                                                                                           
                  166     __tzname_cur_max = len1;                                                                                             
                  167 }
                  
                  1 Reply Last reply
                  0

                  4/8

                  19 May 2018, 19:17

                  • Login

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