Suppose I have:
QString x;
Is the following code fragment:
if(x.compare("abcdefg") == 0){
doSomething();
}
else{
doSomethingElse();
}
... functionally equivalent to:
if(x == "abcdefg"){
doSomething();
}
else{
doSomethingElse();
}
I could prove this for myself by writing a fairly trivial program and executing it, but I was surprised I couldn't find the question / answer here, so I thought I'd ask it for the sake of future me / others.
QVariantgot to do with anything? You're operating on aQStringinstance, the fact that you got it fromQVariantis quite immaterial here because you obtain it the same way in both cases. It doesn't even matter thatcanConvert<QString>returns true. You'll get valid results when it returns false, too. Besides, why do you care whatcomparereturns? You want to compare strings, use theoperator==, it's what it's for.