Creating and Maintaining dynamic array of QLists - How to?
-
Need to maintain multiple QLists. QLists to be created based on need and the pointers to the QLists are to be maintained as a dynamic array. So that an QList element can be pushed or popped based on need.
Is it possible to maintain a dynamic array of QList?
QList<MyClass*> * m_pMyClass;
QVector<m_pMyClass> MyClassArray;So based on need, create a m_pMyClass = new QList<MyClass*>; and push it to MyClassArray?
Note: Just a beginner. Not so good with syntax
-
Need to maintain multiple QLists. QLists to be created based on need and the pointers to the QLists are to be maintained as a dynamic array. So that an QList element can be pushed or popped based on need.
Is it possible to maintain a dynamic array of QList?
QList<MyClass*> * m_pMyClass;
QVector<m_pMyClass> MyClassArray;So based on need, create a m_pMyClass = new QList<MyClass*>; and push it to MyClassArray?
Note: Just a beginner. Not so good with syntax
@darthana said in Creating and Maintaining dynamic array of QLists - How to?:
Is it possible to maintain a dynamic array of QList?
Yes, it is.
"QVector<m_pMyClass> MyClassArray;" - this is invalid C++ because m_pMyClass is a variable, not a type.What you need is:
QVector<QList<MyClass*>> MyClassArray;
To add a new QList to MyClassArray:
MyClassArray.append(new QList<MyClass*>());
-
Need to maintain multiple QLists. QLists to be created based on need and the pointers to the QLists are to be maintained as a dynamic array. So that an QList element can be pushed or popped based on need.
Is it possible to maintain a dynamic array of QList?
QList<MyClass*> * m_pMyClass;
QVector<m_pMyClass> MyClassArray;So based on need, create a m_pMyClass = new QList<MyClass*>; and push it to MyClassArray?
Note: Just a beginner. Not so good with syntax
-
@darthana said in Creating and Maintaining dynamic array of QLists - How to?:
Is it possible to maintain a dynamic array of QList?
Yes, it is.
"QVector<m_pMyClass> MyClassArray;" - this is invalid C++ because m_pMyClass is a variable, not a type.What you need is:
QVector<QList<MyClass*>> MyClassArray;
To add a new QList to MyClassArray:
MyClassArray.append(new QList<MyClass*>());
-
I have created a QList<QList<MyClass*>> MyClassList;
Just struggling to keep going.Consider I need to create multiple instances of MyClass and store it in a QList.
Also need to create multiple QLists mentioned above and store them in MyClassList.How can I access a particular instance of MyClass from MyClassList? I understand a selection of QList inside MyClassList has to be done but not sure on syntax
-
I have created a QList<QList<MyClass*>> MyClassList;
Just struggling to keep going.Consider I need to create multiple instances of MyClass and store it in a QList.
Also need to create multiple QLists mentioned above and store them in MyClassList.How can I access a particular instance of MyClass from MyClassList? I understand a selection of QList inside MyClassList has to be done but not sure on syntax
-
@darthana
Just so you know, you can also maintain a list of lists rather than an array/vector if you wish:QList<QList<MyClass*>> MyClassList;
There is not much difference between a
QList
and aQVector
, especially if you are at Qt6. -
@JonB Just noticed that QVector simply inherits QList in Qt6 and does not have a single extra definition.
https://doc.qt.io/qt-6/qvector.html#details
std::list and std::vector have quite some differences.@JoeCFD said in Creating and Maintaining dynamic array of QLists - How to?:
@JonB Just noticed that QVector simply inherits QList in Qt6 and does not have a single extra definition.
That's why I wrote:
There is not much difference between a
QList
and aQVector
, especially if you are at Qt6.They essentially made them the same at Qt6.
-
@JoeCFD said in Creating and Maintaining dynamic array of QLists - How to?:
@JonB Just noticed that QVector simply inherits QList in Qt6 and does not have a single extra definition.
That's why I wrote:
There is not much difference between a
QList
and aQVector
, especially if you are at Qt6.They essentially made them the same at Qt6.
-
D darthana has marked this topic as solved on