How can I connect a QPushButton and a QComboBox?
I created a SLOT that accepts 2 parameters, a pointer to the QComboBox and the index of the selected item:
void modificaExp::eliminaExp(QComboBox *combo,int value)
{
......
combo->removeItem(value);
....
}
the widgest are there:
QComboBox* combo=new QComboBox();
combo->addItem("ciao1");
combo->addItem("ciao44");
combo->addItem("ciao222");
combo->addItem("ciao555");
QPushButton* delButton=new QPushButton();
delButton->setText("delete");
connect(delButton, SIGNAL(clicked()), this, SLOT( eliminaExp(combo,combo->currentIndex() )));
so, when I click on delButton the element stays there. I think there is a problem in the connect command, specifically I think than the slot is not called.
connectdoes not work this way. If you're using Qt4, you'll have to passcomboboxto a slot somehow (make it a class member, or viasetProperty). If you're using Qt5, you can switch to a 'new' version ofconnectand write a lambda. - Amartel