Qt:将受保护的 QListWidget::itemChanged 信号连接到插槽 [英] Qt: Connecting protected QListWidget::itemChanged signal to a slot

查看:94
本文介绍了Qt:将受保护的 QListWidget::itemChanged 信号连接到插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据新的连接语法在Qt5中使用了以下语法,以避免插槽和信号的类型不匹配对于带有可检查项的 QListWidget.

I used below syntax in Qt5 according to new connect syntax to avoid type mismatches of slot and signals for a a QListWidget with checkable items.

connect(item, &QListWidget::itemChanged,this , &mainWindow::checkItemChanged);

我想运行我的插槽,以防任何列表项更改其状态.为此,由于 this answer,我使用了 itemChanged 信号,但它受到保护并且编译时错误如下:

I want to run my slot in case any of list item changed its state. In order to this this I used itemChanged signal due to this answer, but it is protected and compile time error raise as below:

error: ‘void QListWidget::itemChanged(QListWidgetItem*)’ is protected

我该如何处理?我应该继承我自己的 QListWidget 还是有其他一些解决方案?

How can I handles this? Should I subclass my own QListWidget or there are some other solutions to this?

推荐答案

可以根据Qt版本使用更合适的语法:

You can use the more appropriate syntax according to Qt version:

#if QT_VERSION >= 0x050000
    connect(item, &QListWidget::itemChanged, this , &MainWindow::checkItemChanged);
#else
    connect(item, SIGNAL(checkItemChanged), this , SLOT(checkItemChanged));
#endif

(或所有版本的旧的基于字符串").

(or the 'old string-based' for all versions).

这篇关于Qt:将受保护的 QListWidget::itemChanged 信号连接到插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆