Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.2.0
-
Validated: Win 8, MSVC 2012 & MSVC 2013, Linux GCC
Description
If a Null QVariant is converted into a string, it has to be an empty QString (according to Qt 5.2 docs).
Instead of an emtpy String, Qt 5.2.0 converts an NULL QVariant into QString which contains '0' and has thus a length() of 1.
According to docs, a NULL Variant has to be converted into an empty QString.
!!! However, !!!
even the documented behaviour should be improved:
There is a historical (and useful!) distinction between NULL variables and empty variables. Currently QVariant has to return an empty string, if QVariant ist NULL. This should be adapted to return also an NULL QString, since QString does support already the difference of empty (QString::isEmpty()) and NULL (QString::isNull()).
How you can reproduce the problem:
// According Qt 5.2 doc this creates a NULL Variant of type integer:
QVariant variant(QVariant::Int);
qDebug() << "variant:" << variant;
qDebug() << "variant.isValid?:" << variant.isValid(); // as expected: null variants are valid.
qDebug() << "variant.isNull?:" << variant.isNull(); // as expected, it is null
qDebug() << "variant.toString():" << variant.toString(); // oops: should not return a '0' -> wrong
qDebug() << "variant.toString().isEmpty?:" << variant.toString().isEmpty(); // is not empty, but it should be according docs -> wrong
qDebug() << "variant.toString().isNull?:" << variant.toString().isNull(); // Is not null -> OK according docs, but should be improved.
qDebug() << "variant.toString().length:" << variant.toString().length(); -> length == 1, should be 0 -> wrong