簡體   English   中英

如何將QAction從QMenu傳遞到Qt插槽

[英]How to pass a QAction to a Qt slot from a QMenu

我是Qt的新手,我在如何將QAction作為像這樣的代碼的參數傳遞方面遇到問題:

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

這是我的廣告位功能:

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

QObject::connect不能這樣工作。 您不能將對象傳遞給SIGNALSLOT宏。 SIGNALSLOT宏應帶有函數簽名。 此外the signature of a signal must match the signature of the receiving slot Qt文檔中所述the signature of a signal must match the signature of the receiving slot

我發現您缺乏對信號和插槽機制的理解,建議您閱讀Qt信號和插槽文檔以獲取更多信息。 閱讀Qt Signals and Slots文檔將為您清除所有內容。

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM