[Interest] Strange behaviour with QtextCodec::toUnicode

arnaud but sdnetwork at gmail.com
Sat Aug 4 05:28:29 CEST 2012


i have reported last year on the tracker a strange behaviour with this 
function : https://bugreports.qt-project.org/browse/QTBUG-23139.

in fact a string empty is also null.

For exemple :

#include <QCoreApplication>
#include <QTextCodec>
#include <QDebug>
int main(int argc, char *argv[])
     QCoreApplication a(argc, argv);
     QTextCodec *_code = 
     QString _t = _code->toUnicode("");
     qWarning() << "codec toUnicode" << _t.isEmpty() << _t.isNull();
     // return true  and true; bad
     _t = QString::fromUtf8("");
     qWarning() << "fromUtf8" << _t.isEmpty() << _t.isNull();
     // return true and false; good

     return a.exec();

it causes problems with database driver because when a QString is empty 
the driver database can put null into the database.

as i say in the bug tracker the problem seems to be in qsimplecodec.cpp 
in the function convertToUnicode.

More information about the Interest mailing list