Skip to content

PythonQt.Qt.QBitArray

QBitArray

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

A QBitArray is an array that gives access to individual bits and provides operators (AND, OR, XOR, and NOT) that work on entire arrays of bits. It uses implicit sharing (copy-on-write) to reduce memory usage and to avoid the needless copying of data.

The following code constructs a QBitArray containing 200 bits initialized to false (0):

QBitArray ba(200);

To initialize the bits to true, either pass true as second argument to the constructor, or call fill() later on.

QBitArray uses 0-based indexes, just like C++ arrays. To access the bit at a particular index position, you can use operator[](). On non-const bit arrays, operator[]() returns a reference to a bit that can be used on the left side of an assignment. For example:

QBitArray ba;
ba.resize(3);
ba[0] = true;
ba[1] = false;
ba[2] = true;

For technical reasons, it is more efficient to use testBit() and setBit() to access bits in the array than operator[](). For example:

QBitArray ba(3);
ba.setBit(0, true);
ba.setBit(1, false);
ba.setBit(2, true);

QBitArray supports & (AND), | (OR), ^ (XOR), ~ (NOT), as well as &=, |=, and ^=. These operators work in the same way as the built-in C++ bitwise operators of the same name. For example:

QBitArray x(5);
x.setBit(3, true);
// x: [ 0, 0, 0, 1, 0 ]

QBitArray y(5);
y.setBit(4, true);
// y: [ 0, 0, 0, 0, 1 ]

x |= y;
// x: [ 0, 0, 0, 1, 1 ]

For historical reasons, QBitArray distinguishes between a null bit array and an empty bit array. A null bit array is a bit array that is initialized using QBitArray's default constructor. An empty bit array is any bit array with size 0. A null bit array is always empty, but an empty bit array isn't necessarily null:

QBitArray().isNull();           // returns true
QBitArray().isEmpty();          // returns true

QBitArray(0).isNull();          // returns false
QBitArray(0).isEmpty();         // returns true

QBitArray(3).isNull();          // returns false
QBitArray(3).isEmpty();         // returns false

All functions except isNull() treat null bit arrays the same as empty bit arrays; for example, QBitArray() compares equal to QBitArray(0). We recommend that you always use isEmpty() and avoid isNull().

Source: https://doc.qt.io/archives/qt-5.15/qbitarray.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
at function (self, i: int) -> bool X.at(i) -> bool (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clear function (self) -> None Clears the contents of the bit array and makes it empty. (shared captured text)
clearBit function (self, i: int) -> None Sets the bit at index position i to 0. (shared captured text)
count function (self, on: Any) -> int X.count(on) -> int (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
fill function (self, val: bool, first: Any, last: Any) -> Any X.fill(val, first, last) (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isEmpty function (self) -> bool X.isEmpty() -> bool (shared captured text)
isNull function (self) -> bool X.isNull() -> bool (shared captured text)
operator_assign function (self, other: Any) -> Any X.operator_assign(other) -> PythonQt.QtCore.QBitArray (shared captured text)
readFrom function (self, arg__1: Any) -> Any (shared captured text)
resize function (self, size: int) -> None Resizes the bit array to size bits. (shared captured text)
setBit function (self, i: int, val: Any) -> None X.setBit(i, val) (shared captured text)
size function (self) -> int X.size() -> int (shared captured text)
swap function (self, other: Any) -> None Swaps bit array other with this bit array. (shared captured text)
testBit function (self, i: int) -> bool X.testBit(i) -> bool (shared captured text)
toggleBit function (self, i: int) -> bool X.toggleBit(i) -> bool (shared captured text)
truncate function (self, pos: int) -> None Truncates the bit array at index position pos. (shared captured text)
writeTo function (self, arg__1: Any) -> Any (shared captured text)