Pergunta

Why does the size of QBitArray stay zero? I am using Qt 5.0.2.

QByteArray bytes(4,'b'); // four bytes
QBitArray bits;
QDataStream stream(&bytes, QIODevice::ReadWrite);

stream >> bits;

qDebug() << bytes.size() << bits.size();
Foi útil?

Solução

When reading from a QDataStream it expects the data to be in a certain format, as described at http://qt-project.org/doc/qt-5.0/qtcore/datastreamformat.html. In the case of streaming QBitArray this is:

The array size (quint32)
The array bits, i.e. (size + 7)/8 bytes

If this is not the case the operation will fail - you can check QDataStream::status() to detect errors.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top