Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Compare QString With integers???
Qt 6.11 is out! See what's new in the release blog

Compare QString With integers???

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 3 Posters 2.6k Views 1 Watching
  • 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 Offline
    R Offline
    rajatgupta431
    wrote on last edited by
    #1

    Can Someone guide me how can i compare a QString with integers .

    Somthing like :
    QString str;
    str has some number , then how do i check if it falls in certain range???

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You may use QRegExp for checking. An example is given in "this post":http://qt-project.org/forums/viewthread/5736/#34201 for integer range of 0-255 as in IP addresses. However, you have to answer the question for yourself if it is worth the effort. An alternative may the conversion to integer and an integer comparison. Especially for more complicated things it might be better.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rajatgupta431
        wrote on last edited by
        #3

        Thanks koahnig!
        I used QString::toInt() and it really worked for me :)

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

          Hi,

          Don't forget to check for the bool output of toInt(), to ensure that you really are getting an integer from your string.

          Also, please mark the thread as solved if it is all good for you :)

          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