QList with unknown number of items
-
I am using a Qlist declared as follows:
QList <QWidget *> List_a;
Of course I can add items with List_a.append(W1);
assuming W1 is a Widget declared before
but my concern is that I do not know how many Widget I will have to add
to List_a (depending of a file content read before).How could I create these widgets in a loop and then add to the Qlist ?
-
Hi
You mean new them ?
for (int c=0; c < 100; c++) {
List_a.append( new QPushButton );
}
would add 100 push buttons.However, what will you you use the widgets for ?
If you assign them a parent, and delete parent, then it will
delete the Widgets too and list would contain invalid pointers.So what are you planning to do with these widgets ?