How can I call a function when an item in combobox has changed?

connect(ui->ComboBox,SIGNAL(currentIndexChanged()),this,SLOT(switchcall())); 

in qt, I have no combobox elements, server, client.when I select one of them, it should call the switchcall function. In this function, I want to complete the task depending on the choice in combobox.how to do it ??

+7
source share
2 answers

You did not put args in the SIGNAL / SLOT statements.

 connect(ui->ComboBox,SIGNAL(currentIndexChanged(const QString&)), this,SLOT(switchcall(const QString&))); 

Alternatively, you can use the element index using an overloaded signal.

+15
source

To get the index from the QComboBox change event of a QComboBox element, use:

 connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); 

in mainwindow.h:

 private slots: void indexChanged(int index); 

in mainwindow.cpp:

 void MainWindow::indexChanged(int index) { // Do something here on ComboBox index change } 
+1
source

All Articles