当组合框中的项目发生变化时,如何调用函数?

Ama*_*mar 7 qt combobox qt4

connect(ui->ComboBox,SIGNAL(currentIndexChanged()),this,SLOT(switchcall()));
Run Code Online (Sandbox Code Playgroud)

在qt,组合框项目我没有,服务器,客户端.当我选择其中一个它应该调用switchcall function.in这个功能我想执行任务取决于在combobox.how中的选择来做到这一点?

cma*_*t85 15

你没有把args放在SIGNAL/ SLOTstatements中.

connect(ui->ComboBox,SIGNAL(currentIndexChanged(const QString&)),
        this,SLOT(switchcall(const QString&)));
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用重载信号使用项目索引.


Fut*_*eJJ 6

要从 QComboBox 项目的 QComboBox 更改事件获取索引,请使用:

connect(ui->comboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(indexChanged(int)));
Run Code Online (Sandbox Code Playgroud)

在主窗口.h 中:

private slots:
    void indexChanged(int index);
Run Code Online (Sandbox Code Playgroud)

在主窗口.cpp中:

void MainWindow::indexChanged(int index)
{
    // Do something here on ComboBox index change
}
Run Code Online (Sandbox Code Playgroud)