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.
-
I think QString wants (const char *) 0 for a Null string.
-
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. -
Hm, strange. Could you check if it is defined at all?
@
#if defined(QT_NO_CAST_FROM_ASCII)
#error "QT_NO_CAST_FROM_ASCII is defined"
#else
#error "QT_NO_CAST_FROM_ASCII is NOT defined"
#endif
@ -
I will tomorrow when sober ;-)
-
@Volker: error: #error "QT_NO_CAST_FROM_ASCII is NOT defined"
What is your Qt version? Mine is 4.7.3 -
Ok, just replaced all occurrences with QString()
And it seems that QString snork = 0 only doesn't work for method declarations.
@void doSomething(QString snork1, QString snork2 = 0);@