Set NULL QString
-
Just tried to compile some old code and get: error: call of overloaded ‘QString(int)’ is ambiguous
Maybe I missed something but since when can't we set a null string with @QString snork = 0
QString snork = NULL@
Only this seems to work @QString snork = QString()@Searched all over but can't find anything about any changes except that QString::null has gone, but never used it.
-
Or the empty constructor. The API docs has a nice "comparison between null and empty strings":http://doc.qt.nokia.com/4.7/qstring.html#distinction-between-null-and-empty-strings
0 or NULL is a null pointer, not an object ;-)
PS:
In sofar it is sufficient to write@
QString snork;
@as that calls the empty constructor anyways :-)
-
This code compiles and works as expected for me:
@
QString snork;
QString mumin = NULL;
QString lillemy = 0;qDebug();
qDebug() << "snork:" << snork << snork.isNull() << snork.isEmpty();
qDebug() << "mumin:" << mumin << mumin.isNull() << mumin.isEmpty();
qDebug() << "lillemy:" << lillemy << lillemy.isNull() << lillemy.isEmpty();// output is
snork: "" true true
mumin: "" true true
lillemy: "" true true
@The source for that constructor (resp. the method that's called) checks for a null pointer and constructs a null QString then.
BUT
If I add this to my .pro file the compilation fails:@
DEFINES += QT_NO_CAST_FROM_ASCII
@Maybe you switched the automatic cast from ASCII off?
-
[quote author="Volker" date="1312992977"]
If I add this to my .pro file the compilation fails:@
DEFINES += QT_NO_CAST_FROM_ASCII
@Maybe you switched the automatic cast from ASCII off?
[/quote]
Not that I'm aware, I just created a new Widget Gui Project no DEFINES in it.