QBitArray is a device for managing an arbitrary length list of single-bit flags, not general bit manipulations. There is no obvious way to construct a QBitArray from a preexisting integer that does not involve solving the bit access problem manually first.
char c = 0xaa; // 1010 1010
for (int i = 0; i < 8; ++i)
qDebug() << "Bit" << i << ":" << ((c >> i) & 0x01);
char bit34 = (c & 0x18); // you may want to right shift these >> 3
// clear bits 3 and 4
c = (c & ~0x18);
// set bits 3 and 4
c = (c | 0x18);
char c = 0xaa; // 1010 1010
for (int i = 0; i < 8; ++i)
qDebug() << "Bit" << i << ":" << ((c >> i) & 0x01);
char bit34 = (c & 0x18); // you may want to right shift these >> 3
// clear bits 3 and 4
c = (c & ~0x18);
// set bits 3 and 4
c = (c | 0x18);
To copy to clipboard, switch view to plain text mode
Bookmarks