QDateTime Troubles.

  • Hello,
    I found out some problems in using the QDateTime class within the simplest code (a form, a button, some further line codes for test).
    I'm running my QT Creator 3.3.0 (Qt 5.4.0) under Windows 10 and I couldn't try the same code under other operating systems yet.
    I got my first strange results in trying to extract some file data through the QFileInfo class: all the QDateTime results (i.e. lastModified,lastRead,created methods on an existing file) gives me the starting time "Jenuary 1st 1970, 00:00:00".
    I tried to use the QDateTime class directly, having the same results:

    QDateTime theCurrentDateTime = QDateTime::currentDateTime();
    QDateTime theCurrentDTUTC = QDateTime::currentDateTimeUtc();

    both are set to the same Jenuary the 1st 1970 at midnight!

    I also tried the QDate and QTime classes that gave me the expected result:

    QDate theCurrentDate = QDate::currentDate();
    QTime theCurrentTime = QTime::currentTime();

    Thanx for paying me attention, hope this could be useful.
    Giuseppe Micheli.

  • Moderators

    can you retry with the latest Qt version?
    Have you compiled Qt yourself? If no, i suspect a Qt bug...

  • Hi @giuseppe-micheli, and welcome :)

    That does sound like an odd problem, possibly specific to the machine you're on.

    Out of curiosity, how are you checking the value of the QDateTime? What does it show if you simply stream the QDateTime to qDebug like:

    const QDateTime theCurrentDTUTC = QDateTime::currentDateTimeUtc();
    qDebug() << theCurrentDTUTC;

  • Hi mates.
    First of all thank u a lot for your immediate replies.
    I updated my Qt environment to the 3.5.1 version for Qt Creator (based on Qt 5.5.1) and the problem has been solved.
    Paul, I debugged the call to the (static) currentDateTimeUtc using the creator internal debugger and having the same troubles; I have the old version still on my PC, so, if you wanna me to make any further attempts feel free to ask me.
    Thank you very much again.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.