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. Comparing contents of two Qfile(.txt)

Comparing contents of two Qfile(.txt)

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.4k 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.
  • S Offline
    S Offline
    shree_121
    wrote on last edited by
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • S shree_121

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      0
      • S Offline
        S Offline
        shree_121
        wrote on last edited by
        #3

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

        jsulmJ 1 Reply Last reply
        0
        • S shree_121

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          2
          • S Offline
            S Offline
            shree_121
            wrote on last edited by
            #5

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

            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