Filling QBitArray with data
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.
Re: Filling QBitArray with data
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.
Re: Filling QBitArray with data
Quote:
Originally Posted by
high_flyer
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.
Quote:
Originally Posted by
high_flyer
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
Re: Filling QBitArray with data
Quote:
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/...ode-characters