Qt Forum

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

    Qt Academy Launch in California!

    Solved Comparing contents of two Qfile(.txt)

    General and Desktop
    2
    5
    754
    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
      shree_121 last edited by

      I have two files I get the text from two files in two variables as line and line1. I want compare two variables by if statement
      content of file:line=9 and line=31
      if (line > line1) {
      addto_logging ("line is greater than line1")
      }
      still line is less than line1, Qt output is line is greater than line1 that means it just comparing 9 and 3 not 9 and 31. what wrong here?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @shree_121 last edited by

        @shree_121 Wrong is here the way you're comparing. Strings are compared lexically (character by character, it does not interpret content): https://doc.qt.io/Qt-5/qstring.html#operator-gt

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • S
          shree_121 last edited by

          @jsulm thank you, is there any way other way that i can convert content file in integer format sothat easy to compare big values.

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @shree_121 last edited by

            @shree_121 Sure, but you will need to parse the strings by yourself to locate the numbers, then you can convert them using https://doc.qt.io/Qt-5/qstring.html#toInt

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 2
            • S
              shree_121 last edited by

              @jsulm Thank you so much this exactly what i want.

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