I tried to create a list of buttons using for loop as follow:
Mywidget::Mywidget()
{
for (int i = 0; i < 5; ++i) {
h_layout->addWidget(close_button);
}
}
Mywidget::Mywidget()
{
QVBoxLayout *h_layout=new QVBoxLayout(this);
QPushButton *close_button=new QPushButton[4];
for (int i = 0; i < 5; ++i) {
close_button[i]=new QPushButton("Close",this);
h_layout->addWidget(close_button);
}
}
To copy to clipboard, switch view to plain text mode
But the following error appears:
error
: no match
for 'operator=' (operand types are
'QPushButton' and
'QPushButton*')close_button
[i
]=new QPushButton("Close",
this);
^
error: no match for 'operator=' (operand types are 'QPushButton' and 'QPushButton*')close_button[i]=new QPushButton("Close",this);
^
To copy to clipboard, switch view to plain text mode
But if i removed
close_button[i]
close_button[i]
To copy to clipboard, switch view to plain text mode
and make it only
close_button
close_button
To copy to clipboard, switch view to plain text mode
it create the required button, but the problem here that i can not use every pointer to do specific thing for example :
connect(close_button[2],SIGNAL(clicked(bool)),qApp,SLOT(quit()));
connect(close_button[2],SIGNAL(clicked(bool)),qApp,SLOT(quit()));
To copy to clipboard, switch view to plain text mode
Please help
Bookmarks