
Originally Posted by
ayanda83
Hi there, I want to compare two strings in an if statement condition as follows
if(meta->className() == "MyClass"){ //then do something}
if(meta->className() == "MyClass"){ //then do something}
To copy to clipboard, switch view to plain text mode
but the problem I am having is that meta->className() returns a string of type const char* which is incompatible to
QString. Because of this, the "if" condition does not even evaluate instead it gives a warning - see attached picture
warning.png
Qt4/Qt5 way:
if(meta->className() == QLatin1String("MyClass")) { ... }
To copy to clipboard, switch view to plain text mode
Qt5 only way:
if(meta->className() == QStringLiteral("MyClass")) { ... }
if(meta->className() == QStringLiteral("MyClass")) { ... }
To copy to clipboard, switch view to plain text mode
Bookmarks