View Full Version : What is the best small 2-dim QT container?

21st September 2011, 23:14

I was wondering what would be the smallest and fastest 2-dimensional QT container?
I’m looking for something that will hold arrays of 60×60 up to 200×200 elements.
The values stored in the array would be 0,1,2 or I could split one big array to two same size arrays holding 0 and 1.

I’ve thought about using QVector< QVector<short> > or two QBitArrays.

The problem with

QVector< QVector<short> >

is that I don’t know how to set it’s size as normally it would go like

QVector<short> vect(100)

Next problem is how to access elements. First thing that comes to my mind is:


As for the QBitArray I couldn’t find any way to make it 2 dimensional.

All I need is reading/writing and maybe filling whole array.

Thank You for all responses.

21st September 2011, 23:30

Regarding QVectors you should initialize them with sizes like this:

QVector< QVector<int> > myVector(100, QVector<int>(100));
and access values like this:

myVector[56][23] = 1;

Dont know about QBitArrays though.
Hope this helps!


21st September 2011, 23:34
Use a one dimensional bit array sized n*n and treat it as a two dimensional array.

21st September 2011, 23:50
Both proposed solutions work very well. Thank You :)