PDA

View Full Version : simple QString comment



TheKedge
13th July 2006, 13:21
may sound trivial to many but...

QString thing("");
makes an empty but non-null string

calling clear() on is makes it both empty and null.
I'm sure that's what it's meant to do but does that make sense?
wouldn't be better to have a clear() that empties the string and a reset() to null it?

I recursively use a string, and need it emptied - do I have to empty my string with thing = "";

maybe it's a bit pedantic?
tell me it's pedantic.
thanks
K

high_flyer
13th July 2006, 13:29
calling clear() on is makes it both empty and null.
Should not.
From the docs:

void QString::clear ()

Clears the contents of the string and makes it empty.


bool QString::isNull () const

Returns true if this string is null; otherwise returns false.

Example:

QString().isNull(); // returns true
QString("").isNull(); // returns false
QString("abc").isNull(); // returns false

Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is whether or not a string contains any data, and this can be determined using isEmpty().

See also isEmpty().