Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Problem to convert datetime to time_t

    General and Desktop
    2
    4
    3695
    Loading More Posts
    • 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.
    • S
      Stefanoxjx last edited by Stefanoxjx

      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

      A 1 Reply Last reply Reply Quote 0
      • A
        ambershark @Stefanoxjx last edited by

        @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.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        S 1 Reply Last reply Reply Quote 2
        • S
          Stefanoxjx @ambershark last edited by

          @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

          A 1 Reply Last reply Reply Quote 0
          • A
            ambershark @Stefanoxjx last edited by

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

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply Reply Quote 0
            • First post
              Last post