[Development] Undeprecating QString::null
Kevin Kofler
kevin.kofler at chello.at
Tue Jan 16 18:38:48 CET 2018
Uwe Rathmann wrote:
> So my first question would be, what is wrong about using QString:null and
> why using QString() is better. My second question then would be if this
> is also for Qt4 ( Qwt 6.1.2 supports all versions >= Qt 4.4 ) and older
> versions of C++ and compilers.
A long long time ago, QString::null used to be a static instance of
QString(). This was more efficient than QString() in a context like this one
where a const QString & is needed, but less efficient in many contexts where
people (ab)used it, e.g.:
QString foo = QString::null;
which should really be just:
QString foo;
Thus, now, QString::null is just a static instance of an empty structure,
and converting that structure to QString is the same as QString(), so there
is no longer any performance benefit from using QString::null. This was
already the case in Qt 4. Even Qt 3.3.8b already had that change.
So just use QString(), or define your own static instance of it if you
really want to microoptimize it that much.
Kevin Kofler
More information about the Development
mailing list