c++ - 使用常量参数连接插槽

标签 c++ qt c++11 lambda signals-slots

需要使用常量参数将复选框连接到 TreeView 中的自定义插槽,如下所示:

connect(checkBox, SIGNAL(clicked(bool)), tableView, SLOT(mySlot(int col, bool)));

第一个参数类型 int 应该是常量,例如 0,1,2...如何在 C++11 中使用新的 Qt 5 连接系统和 lambda 表达式正确编写它?

最佳答案

根据new signal syntax documentation ,它应该是这样的:

connect(checkBox, &CheckBox::clicked,
        [&tableView](bool b) { tableView.mySlot(2, b); });

这里的CheckBoxcheckBox的类型,我们把值2硬编码为mySlot的第一个参数>.

关于c++ - 使用常量参数连接插槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37061492/

相关文章:

c++ - 特定快捷方式不适用于 QT

qt - QML 绑定(bind)到数组元素

python - 将 C++ 类移植到 PyQt

c++ - 将类型导出到 python

c++ - 输出返回编号等于输入字符串单词的字符串

c++ - 我的家庭作业代码中的计算有误。怎么修?

c++ - 谁能解释当前 C++0x 标准草案的这一段?

c++ - uniform_real_distribution 给我超出范围的值

c++ - 为单个线程强制执行语句的相对顺序

c++ - 错误 : Conversion from 'double' to non-scalar type 'Player' requested in function 'int main()' ;