PDA

View Full Version : what is equivalent of an array in QT



ggdev001
26th February 2013, 07:43
Hi, in iOS there is NSMutableArray which is a dynamic array of any type of objects.
I think the best equivalent in Qt would be QVariantList right?? Thanks.

ChrisW67
26th February 2013, 09:01
Or QVector<QVariant> if the list is fixed or relatively static in length.

lanz
26th February 2013, 09:10
In Qt and in C++ there's no NSObject. So there is no direct alternative.
What you should use is then depends on what you want to do.
If you want to store value-types and pass them to scripts, you should use QVariantList.
If you want to to store widgets, you should use one of the Qt template container and store pointers, for example QList<QWidget*>.
More general case for non-gui elements is container with QObject*.

wysota
26th February 2013, 09:14
Technically speaking QVariant can also hold a pointer to QObject (or QWidget).

ggdev001
26th February 2013, 10:34
Or QVector<QVariant> if the list is fixed or relatively static in length.

there maybe cases when the array is not fixed in length...

wysota
26th February 2013, 11:57
there maybe cases when the array is not fixed in length...

What matters is if you often insert into the middle of the array or not. Appending at the end is relatively cheap with QVector. If you want to frequently insert in the middle, it is better to use QList.