PDA

View Full Version : Filling QBitArray with data



SpiceWeasel
19th May 2017, 14:19
I'd like to use QBitArray to store raster data that I have in files. However, the class doesn't seem to have the means to initialize or fill itself from a pre-existing buffer. Am I missing something here?

Internally, QBitArray uses a private member of class QByteArray. QByteArray has both a deep-copy initializer and a member function that takes a pointer to a pre-existing buffer (that the QByteArray can then access). However, QBitArray doesn't appear to expose its QByteArray.

high_flyer
19th May 2017, 15:35
The usage of QByteArray internally is an implementation detail, not a principal behavior of the QBitArray - that could change in the future, which is why it is not exposed.
However doing a conversion function from QByteArray to QBitArray is rather a trivial thing to do, just few lines of code.

SpiceWeasel
19th May 2017, 19:13
The usage of QByteArray internally is an implementation detail, not a principal behavior of the QBitArray - that could change in the future, which is why it is not exposed.

Yes, I am aware of the usual reasons for not exposing implementation details. However, QBitArray doesn't have similar methods to QByteArray for initialization/fill (in the manner I mentioned). I hoped, in this case, that it would expose the QByteArray.


However doing a conversion function from QByteArray to QBitArray is rather a trivial thing to do, just few lines of code.

Well, I'd definitely like to see those lines of code :)

I've re-read the documentation for both QBitArray and QByteArray and I cannot come up with any way to convert from one to the other.

Thanks

high_flyer
25th May 2017, 22:52
Well, I'd definitely like to see those lines of code
well, if you are familiar with C++ syntax this should be easy:
- iterate over the the QByteArray.
- For each each Byte, you iterate 8 times , and with a bit operation you extract one bit, which you assign to the next QBitArray element (which you simply increment).

This will work, but might not be the most efficient way to do it - it will do for starters though.

EDIT:
Found this which basically is the same as I said:
https://stackoverflow.com/questions/20445445/qbytearray-to-qbitarray-to-qbytearray-to-qstring-unicode-characters