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. QDateTime with invalid QTime

QDateTime with invalid QTime

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.9k 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.
  • V Offline
    V Offline
    VivienDelmon
    wrote on last edited by
    #1

    Hi,

    With Qt4 I was using QDateTime as a structure to store a QDate and a QTime with sometime an invalid QTime like this :
    @QDateTime dt;
    dt->setDate(2000,1,1);
    dt->setTime(QTime());
    dt->time().isValid() // == false@

    In Qt5 this code does not behave the same and always force the time part of the QDateTime to 00:00:00
    @QDateTime dt;
    dt->setDate(2000,1,1);
    dt->setTime(QTime());
    dt->time().isValid() // == true@

    Is this behavior a regression ? or the QDateTime is not meant to be used like this ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      It is otherway round. They have corrected the issue which was existing Qt 4.x.

      Both 4.x and 5.x documentation says time is invalid if you create QTime() with no arg constructor. i.e isValid() is supposed to return false and which is logical also.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Which version of Qt are you using ? With the latest 5 and 4 I have the same correct result.

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

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VivienDelmon
          wrote on last edited by
          #4

          Hi,

          I am using Qt 5.2.1 and Qt 4.8.4

          What is the correct result ?

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            According to me 5.2.1 is correct behaviour.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Currently running the latest 5.3 and 4.8.6 and getting false in both case, which is correct since you are setting an invalid QTime.

              Since your code snippet contains code that can't be compiled, are you sure you are not doing something funky in your original work ?

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

              1 Reply Last reply
              0

              • Login

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