如何将 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
不是这样工作的。不能将对象传递给宏SIGNAL
和SLOT
宏。 SIGNAL
和SLOT
宏应采用函数签名。此外,the signature of a signal must match the signature of the receiving slot
如Qt
文档中所述。
发现您缺乏对信号和插槽机制的理解,我建议您阅读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);
}
相关文章:
- QT 插槽未在主线程上调用
- Qt插槽调用了两次
- 当再次触发信号时,从Qt插槽执行的功能被第二次调用时会发生什么?
- 连接来自 C++98 接口的 Qt 插槽和信号,无需 Qt、STL 或 Boost
- 有没有办法调试排队等待对象的Qt插槽调用
- QT插槽未激活
- QT- QT插槽问题
- QT插槽和信号,显示第二形式/窗口
- QT插槽未在多线程DLL中执行
- 调试QT插槽未调用
- Qt插槽参数已损坏
- 如何使用Qt插槽中的QwtPplot绘制
- 如何将 QAction 从 QMenu 传递到 Qt 插槽
- Qt 插槽和信号语法
- 如何映射到重载Qt插槽
- Qt插槽,没有用于调用的匹配功能
- Qt插槽调用两次
- 调用未连接的Qt插槽.调用未连接的
- 从线程应用程序中的QtScript调用的Qt插槽
- QT插槽问题,链接错误