[Interest] QDataStream null terminated string / Bug or expected behavior?

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Thu Feb 9 18:18:07 CET 2017


Dear all,

I just found out a bug in my code which was due to the way I wrote/read
from QDataStream.

I write a string like that in one program, from a std::string. This uses
the null-terminated char* overload of << :

std::string str("test");
stream << str.c_str();

I read the data like that in another program:

QByteArray ba;
stream >> ba;

Then ba.size() returns 5 and it contains the null character. Therefore,
comparing it to "test" failed.

In the documentation I cannot find a QByteArray & overload of operator >>.
QByteArray is not supposed to be castable to char*. What is happening here?

Thanks for your help!

Best regards,

Etienne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170209/69b47907/attachment.html>


More information about the Interest mailing list