[Qt-interest] Using qDebug with a QBitArray and QDataStream
Thiago Macieira
thiago at kde.org
Wed Feb 2 08:50:47 CET 2011
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!
Here you're sending text to the debugging output. This is expected to work.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110202/18791af0/attachment.bin
More information about the Qt-interest-old
mailing list