How to create an array of objects??
Hi,
I would like to know, if I can create an object array with the objects that I create with QDesigner.
For example, I put 20 of QLabel object; but QDesigner creates them as label1, label2, ..., label20; all with a different name. Of course, this makes harder to reach the objects. I want to put them in an array like QLabel label[20], so that I can reach all of them just by changing index. Can I do that?
(Related post was answered as "No" about 2.5 years ago, but I want to know if there is a change with Qt 4)
Related post: http://www.qtcentre.org/threads/12866-how-we-convert-no-of-pointer-objects-into-a-single-array
Thanks
Re: How to create an array of objects??
It's still the same as far as I'm aware. You can of course create the array in code and associate the objects at runtime, either by direct assignment (x[i] = label1) or using the methods of the main QObject and searching for them (QObject::children). If the labels in particular belong to a layout, the later is pretty easy as the only objects in the layout with be your labels.
Re: How to create an array of objects??
Alternate way is that you create the array/QVector/QList of QLabel (and of course initialize the QLabels) in code (member in the same class as ui or ui*) and you can then add*** them to the rest of the form created with designer.
***you won't see them in designer, the add is done also in code, just add them to the layout you need or create a layout for them and parent the layout with the appropriate Widget from the ui.