qt - QT 使用另一个类的公共插槽
问题描述
我有一个类ArrayToolBar
,它有一个公共成员commandBox
和一个公共函数createArray()
。
class ArrayToolBar : public QToolBar
{
Q_OBJECT
public:
explicit ArrayToolBar(const QString &title, QWidget *parent);
CommandBox* commandBox = new CommandBox();
void createArray();
这是如何createArray()
定义的
void ArrayToolBar::createArray(){
commandBox->setFocus();
connect(commandBox, SIGNAL(returnPressed()), this, SLOT(commandBox->SubmitCommand()));
}
SubmitCommand() 是
CommandBox
类中的公共槽。
我的问题是我收到一个错误:不存在这样的插槽。这是因为我使用了其他类的插槽ArrayToolBar
吗?有办法吗?
解决方案
您可以将新的连接语法与 labmda 表达式一起使用。
Qt 有一篇关于它的好文章。https://wiki.qt.io/New_Signal_Slot_Syntax
最终代码将如下所示:
connect(commandBox, &CommandBox::returnPressed,
this, [=] () {commandBox->SubmitCommand();});
推荐阅读
- codeigniter - Codeigniter - 数据表中的 $sOrder 和 $sLimit
- ssl - 证书如何验证网站所有者的身份?
- c# - 如何使用按钮获取选定的行 ID 并发送 SQL 查询以更新数据库
- python - 将键值对划分为 n 组总和 y 或更小的算法
- javascript - 文档未定义 Node.js
- swift - 具有自定义类型的 Swift Enum 隐式成员表达式
- spring-mvc - 如何使用 Spring Security 在集群环境中维护用户会话
- c# - 在 C# .Net Windows 窗体中更改标签颜色
- python - 使单个字符串成为列表的一部分
- java - 如何将圆角边框应用于表格(单页/多页)?