Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
5.6.0 Beta
-
08775e4bd745276bcc6a5a9fdc4bed7aca225112
Description
In previous Qt version passing of non-empty QByteArray filled with zeroes into QString::fromLatin1 results into empty QString.
For example this code worked correctly in previous Qt release and doesn't work in Qt 5.6 beta:
// modifies data filling it's contents void GetAnsiString(char* data, size_t sz); QByteArray buf(1024, Qt::Uninitialized); GetAnsiString(buf.data(), buf.size()); QString str = QString::fromLatin1(buf); if ( ! str.isEmpty() ) { //... }
The source of the problem is this commit which changed the behaviour of fromLatin1(QByteArray): https://codereview.qt-project.org/#/c/11530/1
Currently the calls QString::fromLatin1(buf) and QString::fromLatin1(buf.data()) will lead to different results in case of buf contains zeroes.
At least this should be documented.
But, IMHO, it's not a good approach to break existing functionality and even make it inconsistent. If someone would like to have a method which handles zeroes inside a buffer then a new method with suitable name should be created.
Link to the issue with a decision to not handle buffers with zeroes inside: https://bugreports.qt.io/browse/QTBUG-38553