Hello!
I've got a problem with buttons and pointers. I need to create dynamically something like "array" of buttons on one of my application windows (each time the window opens). Now I've got some code:
for(int j=0; j<HOW_MANY_BUTTONS; j++)
{
btn[j]->setGeometry(0,0,40,40);
ui->verticalLayout->addWidget(btn[j],Qt::AlignVCenter);
}
QPushButton *btn[HOW_MANY_BUTTONS];
for(int j=0; j<HOW_MANY_BUTTONS; j++)
{
btn[j] = new QPushButton;
btn[j]->setGeometry(0,0,40,40);
ui->verticalLayout->addWidget(btn[j],Qt::AlignVCenter);
}
To copy to clipboard, switch view to plain text mode
It works just fine. But number of buttons is changing, and I don't want to create array of pointers which is bigger or smaller than number of buttons. Any suggestions how should I write function which is creating as many buttons as I need in a moment?
thanks in advance
best regards
Tomasz
Bookmarks