Nominate our 2022 Qt Champions!

What is the best small 2-dim QT container?

  • Hello,

    I was wondering what would be the smallest and fastest 2-dimensional QT container?
    I'm looking for something that will hold arrays of 60x60 up to 200x200 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.

  • You can use this:
    typedef QVector< short > SubContainer;
    const int size = 100;
    QVector< SubContainer > vv( size, SubContainer( size ) ); @

    As you said you can access elements with x ).at( y )@
    or with
    @vv[ x ][ y ]@

Log in to reply