I was not comparing directly, but through a QSet<QByteArray>, which was
initially populated using string litterals. So I inserted "test" but after
reading from the stream I had "test\0"

2017-02-09 22:00 GMT+01:00 Mike Chinander <chinan...@gmail.com>:

> How are you comparing it to "test" after reading to the QByteArray? You
> could use str.data() instead str.c_str(). Or use QStrings to read to/from
> the QDatastreams.
>
> On Thu, Feb 9, 2017 at 11:18 AM, Etienne Sandré-Chardonnal <
> etienne.san...@m4x.org> wrote:
>
>> 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
>>
>> _______________________________________________
>> Interest mailing list
>> Interest@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to