2014-12-02 62 views
1

蔭新的Qt中傳遞給Qt的插槽和我有問題怎麼傳的QAction因爲這樣的代碼參數:如何將的QAction從QMenu

connect(fileToolBarAct, SIGNAL(toggled(bool)), this, SLOT(ToggleBar(fileToolBarAct)); 

這我插槽功能:

void MainWindow::ToggleBar(QAction& what) 
{ 
    what.isCheckable(); 
} 
+0

什麼是錯誤? – 2014-12-02 15:05:53

回答

2

QObject::connect不能這樣工作。您無法將對象傳遞給SIGNALSLOT宏。 SIGNALSLOT宏應該採用函數簽名。另外the signature of a signal must match the signature of the receiving slotQt文檔中所述。

我看到您對理解信號和插槽機制缺乏瞭解,我建議您閱讀Qt Signals and Slots文檔以獲取更多信息。閱讀Qt Signals and Slots文檔將清除您的一切。

0
onnect(fileToolBarAct, SIGNAL(toggled(bool)), this, SLOT(ToggleBar(bool)); 


void MainWindow::ToggleBar(bool checked) 
{ 
    QAction* action = qobject_cast<QOAction*>(sender()); 
    if (action) 
     action->setChecked(checked); 
}