Problem to convert datetime to time_t



  • Hi, I've a problem and I don't understand if it is a bug.
    I would like to convert QDateTime in time_t, but the result is always 4294967295 equivalent to 07 feb 2006 07:28.
    If I work with date/time lower than 07 feb 2006 07:28 the conversion result is good.
    I think that is a bug.

    I use Qt Creator 4.1.0 Based on Qt 5.7.0 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit) under Debian Jessie.

    The code line that should convert date time in time_t is:

    qDebug() << QDateTime(ui->editDTStart->dateTime()).toTime_t();
    

    What do you think?

    ManyThanks

    Stefano


  • Moderators

    @Stefanoxjx Worked fine for me... I used this code to test with qt 5.7 on linux:

    #include <QDateTime>
    #include <QDebug>
    
    int main(int ac, char **av)
    {
            QDateTime dt = QDateTime::currentDateTime();
            qDebug() << "date time is: " << dt.toTime_t();
            QDateTime dt2 = QDateTime::fromTime_t(dt.toTime_t());
            qDebug() << "dt2: " << dt2;
            return 0;
    }
    

    Output was as expected with the current local time and the converted time_t was correct with current local as well.

    My guess is you are getting a bad value from your UI control. No bug that I can find in Qt's QDateTime.



  • @ambershark
    Hello @ambershark and thanks for your help.
    I don't understand what appened, but the same code that did not work well, now it works fine.

    Stefano


  • Moderators

    @Stefanoxjx Oh that's good it is working now... You may just have had a dirty build and after a rebuild things were "fixed". :)


Log in to reply
 

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