Creating and Maintaining dynamic array of QLists - How to?
-
wrote on 3 Jan 2023, 06:11 last edited by darthana 1 Mar 2023, 08:31
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
Lifetime Qt Championwrote on 3 Jan 2023, 07:53 last edited by jsulm 1 Mar 2023, 07:54@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
wrote on 3 Jan 2023, 08:00 last edited by@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. -
@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*>());
-
wrote on 9 Jan 2023, 16:32 last edited by
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.wrote on 9 Jan 2023, 17:16 last edited by@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. -
@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.wrote on 9 Jan 2023, 17:34 last edited by JonB 1 Sept 2023, 17:35@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.
-
3/10