A vector is not meant to behave like an array. Of course there are some solutions.
I found a solution that seems to be getting closer to what you want , see if it helps. It shows how to initialize the array as if it were an array.
There is a Qt class for this but it was considered obsolete and as far as I know nothing was created to replace it. but has a more modern class in version 4.6 onwards.
Another obvious option is to look for a class that will suit you in another library. It may not be as simple to integrate with Qt.
There is still the possibility of creating your class that works as an array. This can bring some integration advantages with Qt depending on how you do it.
I found a gambiarra in this answer in the SO : / p>
int index(int x, int y) {
return x + width * y;
}
So you simulate an array inside the vector:
QVector<...> vector(width * height);
vector[index(5, 3)] = ...;
I placed GitHub for future reference .