简体   繁体   English

如何将QAction从QMenu传递到Qt插槽

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

Iam new in Qt and I have problem how to pass QAction as parameter like this code: 我是Qt的新手,我在如何将QAction作为像这样的代码的参数传递方面遇到问题:

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

And this my slots function: 这是我的广告位功能:

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

QObject::connect doesn't work like this. QObject::connect不能这样工作。 You can not pass objects to SIGNAL and SLOT macros. 您不能将对象传递给SIGNALSLOT宏。 SIGNAL and SLOT macros should take function signatures. SIGNALSLOT宏应带有函数签名。 In addition the signature of a signal must match the signature of the receiving slot as described in the Qt documentation. 此外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

I see that you lack in understanding the signals and slots mechanism and I recommend you read the Qt Signals and Slots documentation for more info. 我发现您缺乏对信号和插槽机制的理解,建议您阅读Qt信号和插槽文档以获取更多信息。 Reading the Qt Signals and Slots documentation will clear everything for you. 阅读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