繁体   English   中英

Qt插槽和信号:MainWindow中没有匹配功能

[英]Qt slot and signal: no matching function in MainWindow

对于此错误“没有匹配函数可调用”,我已经查看了各种Qt讨论,但在这种情况下,我仍然看不到有什么不同。 我已经成功在GUI元素之间设置了插槽/信号对,但是由于某些原因,最新的插槽/信号对集正在创建错误。

为了允许所有GUI元素更新主窗口上的状态栏,我在每个面板中创建了一个信号,如下所示

class PanelA : public QWidget
{
  ...
  public signals:
     void UpdateStatusBar(std::string);
  ...
}

然后在MainWindow中有一个插槽

//from MainWindow.h
class MainWindow : public QMainWindow
{
  private slots:
     void ReceiveStatus(std::string);
}

//from MainWindow.cpp
void MainWindow::ReceiveStatus(std::string s)
{
  //I can provide other controls, filters, etc.
  //but currently there are none
  ui->statusBar->showMessage(tr("System status: "+s));
}

最后,在MainWindow构造函数中,我已经有几个信号,并且为每个GUI元素添加了一条新的连接线。

connect(ui->panelA, &PanelA::SelectionChanged, ui->panelB, &PanelB::UpdateSelection);
//this one works
connect(ui->panelA, &PanelA::UpdateStatusBar, ui, &MainWindow::ReceiveStatus);
//this one generates an error there is one status bar connection for each

因此,据我所知语法是正确的。 ui-> panelA和ui都是指针。 我不知道为什么一个是正确的而另一个是错误的。 我将不胜感激任何建议。

可能应该是:

connect(ui->panelA, &PanelA::UpdateStatusBar, this, &MainWindow::ReceiveStatus);

ui对象不是主窗口,但this会。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM