簡體   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