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. compare 2 QString, use == != ? or QString::compare ?
Forum Updated to NodeBB v4.3 + New Features

compare 2 QString, use == != ? or QString::compare ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 20.6k Views 2 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.
  • O Offline
    O Offline
    opengpu2
    wrote on 12 Mar 2015, 08:26 last edited by
    #1

    compare 2 QString, use == != ? or QString::compare ?
    which way is better and faster?
    thank you

    A 1 Reply Last reply 12 Mar 2015, 08:39
    0
    • M Offline
      M Offline
      Malek_Khlif
      wrote on 12 Mar 2015, 08:30 last edited by
      #2

      I Think == is same QString::Compare because == call operator==() and compare also.

      I Love Qt <3

      1 Reply Last reply
      0
      • O opengpu2
        12 Mar 2015, 08:26

        compare 2 QString, use == != ? or QString::compare ?
        which way is better and faster?
        thank you

        A Offline
        A Offline
        Asperamanca
        wrote on 12 Mar 2015, 08:39 last edited by
        #3

        @opengpu2
        Compare gives you the option to ignore case. Also, operator== only gives you true or false, while compare can be used to sort strings.

        If all you want to do is check that two strings are absolutely equal, I would go for ==

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mcosta
          wrote on 12 Mar 2015, 08:43 last edited by
          #4

          IMO operator==() is faster because, as first thing, it checks if the sizes are the same.
          If you're interested only to test is the string are the same or not, go to == or !=

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          3

          1/4

          12 Mar 2015, 08:26

          • Login

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