This shows how to access the pointer to the raw data in std::vector. I want something like that in Qt for QVector, QQueue and QList (If possible other containers).
For instance if we have some containers:
QVector<int> vector;
QQueue<int> queue;
QList<int> list;
And these pointers:
int * p1 = &vector[0];
int * p2 = &queue[0];
int * p3 = &list[0];
Do the above pointers point to raw data in containers?
For the above case i made a test. The code is:
QVector<int> vector;
QQueue<int> queue;
QList<int> list;
for(int i=0;i<10;i++)
{
vector.append(i);
queue.enqueue(i);
list.append(i);
}
int * P1 = &vector[0];
int * P2 = &queue[0];
int * P3 = &list[0];
for(int i=0;i<10;i++)
qDebug()<<P1[i]<<P2[i]<<P3[i]<<"\n";
And the result is:
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
So at least it is true for the case of int type.
But the same test with double type failed. Just QVector elements were correct for type double.
Is it possible to get pointer to raw data in QQueue and QList?