简体   繁体   English

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

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

I have looked at a variety of the Qt discussions for this error "no matching function for call to" and I still cannot see what is different in this case. 对于此错误“没有匹配函数可调用”,我已经查看了各种Qt讨论,但在这种情况下,我仍然看不到有什么不同。 I have successfully set up slot/signal pairs between GUI elements, but for some reason the latest set of slot/signal pairs is creating an error. 我已经成功在GUI元素之间设置了插槽/信号对,但是由于某些原因,最新的插槽/信号对集正在创建错误。

In order to allow all GUI elements to update the status bar on the main window I have created a signal in each panel as shown here 为了允许所有GUI元素更新主窗口上的状态栏,我在每个面板中创建了一个信号,如下所示

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

Then in MainWindow there is a slot 然后在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));
}

And finally, in the MainWindow constructor I have several signals already and I have added one new connect line for each GUI element. 最后,在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

So, as far as I can tell the syntax is right. 因此,据我所知语法是正确的。 both ui->panelA and ui are pointers. ui-> panelA和ui都是指针。 I don't know why one is correct and the other is wrong. 我不知道为什么一个是正确的而另一个是错误的。 I'd appreciate any suggestions. 我将不胜感激任何建议。

Probably should be: 可能应该是:

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

The ui object isn't a MainWindow, but this will be. ui对象不是主窗口,但this会。

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

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