How to Compare two Qstrings?

krohit picture krohit · Oct 9, 2013 · Viewed 82.3k times · Source

I have to compare two Qstrings in qt,

say,

Qstring str1="1005",str2="1006";

I have tried using ,

if(str1==str2){
   return true;
}

&

if(str1.compare(str2)==0)
{
    return true;
}

still both methods goes inside if condition & returns true.

Answer

mcelik picture mcelik · Oct 9, 2013

You can use :

int x = QString::compare(str1, str2, Qt::CaseInsensitive);  // if strings are equal x should return 0