我正在尝试连接组合框值和标签,以便在组合框更改时标签反映这一点。我已经用谷歌搜索了我的心,试图找到答案,但到目前为止,还没有任何效果;我仍然收到错误:no matching function for call to mainWindow::connect(QComboBox*&, const char [38], QString*, const char [26])
我已经尝试过QObject::connect
,QWidget::connect
以及其他任何与 Qt 打交道的东西,但都无济于事。
创建一个表示组合框值的标签并不是我对该程序的最终意图。相反,我希望让它使用一个简单的标签,然后将其更改为我希望它显示的内容(因此是tempLabel
)。
主窗口.h:
class MainWindow : public QMainWindow
{
public:
MainWindow();
private slots:
QString getClass(QComboBox *box);
};
主窗口.cpp:
MainWindow::MainWindow()
{
QString qMathClassName;
QComboBox* mathClassCombo = new QComboBox;
QLabel* label = new QLabel(qMathClassName);
// omitting layout code...
connect(mathClassCombo, SIGNAL(currentIndexChanged(const QString &)),
&qMathClassName, SLOT(getClass(mathClassCombo)));
}
QString MainWindow::getClass(QComboBox *box)
{
return box->currentText();
}
任何帮助将不胜感激!