Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Solved QDate matching not working Qt5 always getting false

    General and Desktop
    3
    7
    160
    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.
    • R
      rkt1989 last edited by

      I am trying to match which date is greater than another

      I am getting system date using following code

      QDate systemDate = QDate::currentDate();
              QString date1 = systemDate.toString("yyyy/MM/dd");
              QDate systemDate1;
              systemDate1.fromString(date1,"yyyy/MM/dd");
      

      and system event log date

      QString xml = getStringFromEvent(publisherMetaData, nextEvents[i], EvtFormatMessageXml);
                      //winEventList.append(eventInfo);
                      QDomDocument dom;
                      dom.setContent(xml);
                      QString dateTime = dom.elementsByTagName("TimeCreated").at(0).toElement().attribute("SystemTime");
                      QString date = dateTime.section("T", 0, 0);
                      QDate logDate;
                      logDate.fromString(date,"yyyy/MM/dd");
      

      but when i try to compare using following code i always get false even when system date < log date

      if(logDate > systemDate1){
                          clockChanged = true;
                          break;
                      }
      

      can anyone suggest some modification thank you.

      KroMignon 1 Reply Last reply Reply Quote 0
      • KroMignon
        KroMignon @rkt1989 last edited by KroMignon

        @rkt1989 said in QDate matching not working Qt5 always getting false:

        logDate.fromString(date,"yyyy/MM/dd");

        Are you sure date contains a valid date string?
        Check if logdate.isValid() returns true.

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        R 1 Reply Last reply Reply Quote 0
        • R
          rkt1989 last edited by

          qDebug("Hello "+date.toLatin1()+"");
          

          gives me following output
          Hello 2020/09/10
          Hello 2020/09/10
          Hello 2020/09/09

          qDebug("Hello "+date1.toLatin1()+"");
          

          gives me following output

          Hello 2020/09/10

          1 Reply Last reply Reply Quote 0
          • R
            rkt1989 @KroMignon last edited by

            @KroMignon

            logdate.isValid()
            

            is returning false what should i do

            1 Reply Last reply Reply Quote 0
            • Christian Ehrlicher
              Christian Ehrlicher Lifetime Qt Champion last edited by

              @rkt1989 said in QDate matching not working Qt5 always getting false:

              what should i do

              think about why it's the case... Did you check the string?

              Qt has to stay free or it will die.

              R 1 Reply Last reply Reply Quote 1
              • R
                rkt1989 @Christian Ehrlicher last edited by

                @Christian-Ehrlicher ok i fixed that with

                QDate logDate = QDate::fromString(date,"yyyy-MM-dd");
                
                Christian Ehrlicher 1 Reply Last reply Reply Quote 0
                • Christian Ehrlicher
                  Christian Ehrlicher Lifetime Qt Champion @rkt1989 last edited by

                  @rkt1989 Then please mark this topic as solved.

                  Qt has to stay free or it will die.

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