Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qdatetime is not displayed correctly in qt creator (is correct in qDebug output)



  • Summary:
    In the Qt creator debugger, I see incorrect values displayed on a QDateTime. The output from the same QDateTime value is correct when output via qDebug(). How can I correct this?
    debugger qdatetime.png
    Steps to reproduce

    1. Create a new Qt widget project in qt creator, open main.cpp, and add the following code, and set a breakpoint at the last line.
        QDateTime myqdatetime;
        qint64 start = myqdatetime.currentDateTimeUtc().toMSecsSinceEpoch();
        start = 1596782820000; //fixed value: (2020-08-07 08:47:00 localtime in the Netherlands, 2020-08-07 06:47:00 UTC)
    
        QDateTime startdtLt;
        QDateTime startdtUtc;
        qDebug() << start;
        startdtLt=QDateTime::fromMSecsSinceEpoch(start); //debug
        qDebug() << startdtLt;
        startdtUtc=QDateTime::fromMSecsSinceEpoch(start, Qt::UTC,0);
        qDebug() << startdtUtc;
    
    1. Debug the code (press F5), and see the following in the Application output. These are the correct value's:
    11:48:02: Debugging starts
    1596782820000
    QDateTime(2020-08-07 08:47:00.000 W. Europe Daylight Time Qt::LocalTime)
    QDateTime(2020-08-07 06:47:00.000 UTC Qt::UTC)
    
    1. Look at the right plane of qt creator. There wildly incorrect values are displayed:
    startdtLt     za apr 29 20:35:56 1989 GMT+0006
    startdtUtc    do jan 31 07:23:38 1974 GMT+0006
    

    My versions:

    Qt Creator 4.12.0
    Based on Qt 5.14.2 (MSVC 2017, 32 bit)
    Built on Apr 22 2020 01:29:13
    From revision 10fece1795
    Copyright 2008-2020 The Qt Company Ltd. All rights reserved.
    The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    
    Windows 10 Enterprise
    Version 1903
    OS build 18362.959
    

    My compile output:

    11:47:54: Running steps for project qdatetime...
    11:47:54: Starting: "C:\Qt\5.14.2\mingw73_32\bin\qmake.exe" "H:\New folder\qdatetime\qdatetime.pro" -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
    Info: creating stash file H:\New folder\build-qdatetime-Desktop_Qt_5_14_2_MinGW_32_bit-Debug\.qmake.stash
    11:47:55: The process "C:\Qt\5.14.2\mingw73_32\bin\qmake.exe" exited normally.
    11:47:55: Starting: "C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -f "H:/New folder/build-qdatetime-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/Makefile" qmake_all
    mingw32-make: Nothing to be done for 'qmake_all'.
    11:47:56: The process "C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited normally.
    11:47:56: Starting: "C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j12
    C:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory 'H:/New folder/build-qdatetime-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
    C:\Qt\5.14.2\mingw73_32\bin\uic.exe ..\qdatetime\mainwindow.ui -o ui_mainwindow.h
    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\qdatetime -I. -IC:\Qt\5.14.2\mingw73_32\include -IC:\Qt\5.14.2\mingw73_32\include\QtWidgets -IC:\Qt\5.14.2\mingw73_32\include\QtGui -IC:\Qt\5.14.2\mingw73_32\include\QtANGLE -IC:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IC:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\main.o ..\qdatetime\main.cpp
    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\qdatetime -I. -IC:\Qt\5.14.2\mingw73_32\include -IC:\Qt\5.14.2\mingw73_32\include\QtWidgets -IC:\Qt\5.14.2\mingw73_32\include\QtGui -IC:\Qt\5.14.2\mingw73_32\include\QtANGLE -IC:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IC:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\qdatetime\mainwindow.cpp
    g++ -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -dM -E -o debug\moc_predefs.h C:\Qt\5.14.2\mingw73_32\mkspecs\features\data\dummy.cpp
    C:\Qt\5.14.2\mingw73_32\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "H:/New folder/build-qdatetime-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/debug/moc_predefs.h" -IC:/Qt/5.14.2/mingw73_32/mkspecs/win32-g++ -I"H:/New folder/qdatetime" -IC:/Qt/5.14.2/mingw73_32/include -IC:/Qt/5.14.2/mingw73_32/include/QtWidgets -IC:/Qt/5.14.2/mingw73_32/include/QtGui -IC:/Qt/5.14.2/mingw73_32/include/QtANGLE -IC:/Qt/5.14.2/mingw73_32/include/QtCore -I. -IC:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++ -IC:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/i686-w64-mingw32 -IC:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/backward -IC:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include -IC:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include-fixed -IC:/Qt/Tools/mingw730_32/i686-w64-mingw32/include ..\qdatetime\mainwindow.h -o debug\moc_mainwindow.cpp
    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\qdatetime -I. -IC:\Qt\5.14.2\mingw73_32\include -IC:\Qt\5.14.2\mingw73_32\include\QtWidgets -IC:\Qt\5.14.2\mingw73_32\include\QtGui -IC:\Qt\5.14.2\mingw73_32\include\QtANGLE -IC:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IC:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
    g++ -Wl,-subsystem,windows -mthreads -o debug\qdatetime.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  C:\Qt\5.14.2\mingw73_32\lib\libQt5Widgets.a C:\Qt\5.14.2\mingw73_32\lib\libQt5Gui.a C:\Qt\5.14.2\mingw73_32\lib\libQt5Core.a  -lmingw32 C:\Qt\5.14.2\mingw73_32\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-win32\lib -LC:\Utils\postgresql\pgsql\lib -lshell32 
    mingw32-make[1]: Leaving directory 'H:/New folder/build-qdatetime-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
    11:48:02: The process "C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited normally.
    11:48:02: Elapsed time: 00:09.
    ```![debugger qdatetime.png](https://ddgobkiprc33d.cloudfront.net/ae2fdb73-df09-4366-857c-f2ff328be57a.png)

Log in to reply