QSignalMapper is deprecated
今天参考 qt4 的书籍,在 qt5 的平台上面,用了 QSignalMapper,结果收到警告“ QSignalMapper is deprecated"。
经过一番查找,找到了相应的说明, 参考自:https://doc.qt.io/qt-5/qsignalmapper.html
This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
官方建议 qt5 里面使用 lambda 方式表达。
下面是旧的方式:
class ButtonWidget : public QWidget
{
Q_OBJECT
public:
ButtonWidget(const QStringList &texts, QWidget *parent = 0);
signals:
void clicked(const QString &text);
private:
QSignalMapper *signalMapper;
};
ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
: QWidget(parent)
{
signalMapper = new QSignalMapper(this);
QGridLayout *gridLayout = new QGridLayout;
for (int i = 0; i < texts.size(); ++i) {
QPushButton *button = new QPushButton(texts[i]);
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, texts[i]);
gridLayout->addWidget(button, i / 3, i % 3);
}
connect(signalMapper, SIGNAL(mapped(QString)),
this, SIGNAL(clicked(QString)));
setLayout(gridLayout);
}
This class was mostly useful before lambda functions could be used as slots. The example above can be rewritten simpler without QSignalMapper by connecting to a lambda function.
下面是新的方式:
ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
: QWidget(parent)
{
QGridLayout *gridLayout = new QGridLayout;
for (int i = 0; i < texts.size(); ++i) {
QString text = texts[i];
QPushButton *button = new QPushButton(text);
connect(button, &QPushButton::clicked, [=] { clicked(text); });
gridLayout->addWidget(button, i / 3, i % 3);
}
setLayout(gridLayout);
}
QSignalMapper is deprecated的更多相关文章
- [Deprecated!] Android开发案例 - 微博正文
Deprecated! 更好的实现方式: 使用 android.support.design.widget.CoordinatorLayout. 本文详细介绍如何实现如下图中的微博正文页面效果, 其中 ...
- 解决: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19
错误信息:C:\Python27\lib\site-packages\sklearn\utils\validation.py:395: DeprecationWarning: Passing 1d a ...
- 解决 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
转载 php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql ext ...
- 手动建库时一个小错误:ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
此前执行了CREATE SPFILE FROM MEMORY. 重新使用SPFILE启动时,出错如下: SYS@ bys3>startup ORA-32004: obsolete or dep ...
- 解决php deprecated 的问题
Deprecated :意思是“不推荐” php 5.3 从一方面来讲,可以说在07年计划PHP6的中的一个pre版本,增加了很多功能,统一了很多语法,使PHP变得更加强大与简洁. 说到统计架构规划, ...
- ORA-32004: obsolete and/or deprecated parameter(s) specified
如果在启动数据库时遇到ORA-32004: obsolete and/or deprecated parameter(s) specified 错误,这个是因为数据库里面设置了过时或不推荐使用的参数, ...
- java中“@Deprecated”的意思
例如:Java内在的File类中有如下方法 @Deprecatedpublic URL toURL() throws MalformedURLException {return new URL(&qu ...
- >>> FilterDispatcher <<< is deprecated! Please use the new filters!
在struts2.3.20下,web.xml中使用 会出现*********************************************************************** ...
- preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
由于方法preg_replace()为PHP 5.5.x 中废弃的特性,官方建议需要在代码中将preg_replace()替换为函数preg_replace_callback,可以问题解决. 具体请见 ...
随机推荐
- 一 CRM 注册功能实现
前端:登陆页面按钮跳转到注册页面 dao: 配置连接池 配置session工厂,Hibernate核心配置,映射 配置UserDao,注入session工厂 UserDao:继承HibernateD ...
- 线程高级篇-Lock锁实现生产者-消费者模型
Lock锁介绍: 在java中可以使用 synchronized 来实现多线程下对象的同步访问,为了获得更加灵活使用场景.高效的性能,java还提供了Lock接口及其实现类ReentrantLock和 ...
- springboot项目启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedde
参考:https://blog.csdn.net/Coyotess/article/details/80637837
- win7 & win10 安装AD管理工具
总所周知,AD域的作用对于一个公司有着无比重要的作用,但是在Win7/10系统下该如何去管理AD域呢. 对于AD域的服务器搭建,在这里我们不进行说明,感兴趣的同学可以去Google相关的资料,现在主要 ...
- VMware Tools 组件、配置选项和安全要求
- JDK8中的HashMap实现原理及源码分析
大纲 一.什么是Hash?什么是HashMap? 二.HashMap的内部实现机制 1.HashMap基本元素 ①DEFAULT_INITIAL_CAPACITY&MAXIMUM_CAPACI ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-fast-forward
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- Unity 脚本中的update,fixedupdate,lateupdate
先放着 有功儿夫再来整理 https://www.cnblogs.com/fly-100/p/3777731.html https://www.cnblogs.com/hont/p/5184802.h ...
- Docker 搭建开源 CMDB平台 之 “OpsManage”
说明: 我一次build 完 所以images 包 有1G多 可分层build bash 环境一层 应用程序及启动脚本(shell.sh) 一层 步骤: 1 ...
- Python 编写代码 检查是否遵循PEP 8标准
实际上并非必须遵守PEP 8,但是它已经成为一个默认的.约定俗成的规则,可以使代码风格更统一,提高可读性. 由于最近一直在学习Ubuntu,因此此处仍然以Ubuntu为例,介绍一下规则检查工具,它能帮 ...