[Qt-interest] Using qDebug with a QBitArray and QDataStream

Kamil Klimek naresh at tlen.pl
Wed Feb 2 14:17:33 CET 2011


Wiadomość napisana przez Thiago Macieira w dniu 2011-02-02, o godz. 08:50:

> On Wednesday, 2 de February de 2011 08:41:29 Alex Strickland wrote:
>> Hi
>> 
>> Can someone tell me why this doesn't work?:
>> 
>>         QByteArray debugByteArray;
>>         QDataStream debugStream( &debugByteArray, QIODevice::ReadWrite);
>>         QBitArray z( 10 );
>>         z.setBit( 3, true );
>>         debugStream << z;
>>         qDebug() << debugByteArray;
>> 
>> or should I say doesn't do what I expect, the output is:
>> 
>> "
> 
> Right, it does work, it just doesn't output what you expected. You're trying 
> to see the debug output of a binary byte array. What happens here is that 
> there are embedded NULs inside that array and qDebug got confused.
> 
> qDebug is not meant for binary data. It will result in an incomplete output if 
> it gets one.
> 
>> 
>> I know I can do this:
>> 
>> 	QString text;
>> 	for (int i = 0; i < z.size(); ++i)
>>     		text += z.testBit(i) ? "1": "0";
>> 	qDebug() << text;
>> 
>> so this more about my education than solving my problem!

You can write your own qDebug() operator<< for
check here: QBitArray http://doc.qt.nokia.com/4.7/debug.html#providing-support-for-the-qdebug-stream-operator




More information about the Qt-interest-old mailing list