Qt 信号与槽:解决 'no matching function for call to' 错误

信号:

void setListCurrentIndex_sig(int row);
void updataJBList_sig();
void updataText_sig();
void  updataState_sig();

连接菜单项的槽函数:

connect(m_actionReRecord, &QAction::triggered, this, &MainWindow::onReRecord);
connect(m_actionDeleteSelected, &QAction::triggered, this, &MainWindow::onDeleteSelected);
connect(m_actionSelectOnlyThis, &QAction::triggered, this, &MainWindow::onSelectOnlyThis);
connect(m_actionSelectAll, &QAction::triggered, this, &MainWindow::onSelectAll);
connect(m_actionSelectNone, &QAction::triggered, this, &MainWindow::onSelectNone);
connect(m_actionRename, &QAction::triggered, this, &MainWindow::onRename);

错误代码:

void MainWindow::setListCurrentIndex(int row){
    emit pThis->setListCurrentIndex_sig();
}

错误原因: 在 MainWindow::setListCurrentIndex() 函数中,setListCurrentIndex_sig() 函数需要一个 int 类型的参数,但代码中没有传入任何参数,导致编译器无法找到匹配的函数,从而报错 'no matching function for call to '。

解决方案: 在 emit 语句中传递 row 参数:

void MainWindow::setListCurrentIndex(int row){
    emit setListCurrentIndex_sig(row);
}

通过传递 row 参数,代码将能够找到匹配的 setListCurrentIndex_sig() 函数,从而解决 'no matching function for call to' 错误。


原文地址: https://www.cveoy.top/t/topic/nzjt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录