今天参考 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的更多相关文章

  1. [Deprecated!] Android开发案例 - 微博正文

    Deprecated! 更好的实现方式: 使用 android.support.design.widget.CoordinatorLayout. 本文详细介绍如何实现如下图中的微博正文页面效果, 其中 ...

  2. 解决: 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 ...

  3. 解决 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 ...

  4. 手动建库时一个小错误:ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance

    此前执行了CREATE SPFILE FROM MEMORY.  重新使用SPFILE启动时,出错如下: SYS@ bys3>startup ORA-32004: obsolete or dep ...

  5. 解决php deprecated 的问题

    Deprecated :意思是“不推荐” php 5.3 从一方面来讲,可以说在07年计划PHP6的中的一个pre版本,增加了很多功能,统一了很多语法,使PHP变得更加强大与简洁. 说到统计架构规划, ...

  6. ORA-32004: obsolete and/or deprecated parameter(s) specified

    如果在启动数据库时遇到ORA-32004: obsolete and/or deprecated parameter(s) specified 错误,这个是因为数据库里面设置了过时或不推荐使用的参数, ...

  7. java中“@Deprecated”的意思

    例如:Java内在的File类中有如下方法 @Deprecatedpublic URL toURL() throws MalformedURLException {return new URL(&qu ...

  8. >>> FilterDispatcher <<< is deprecated! Please use the new filters!

    在struts2.3.20下,web.xml中使用 会出现*********************************************************************** ...

  9. preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

    由于方法preg_replace()为PHP 5.5.x 中废弃的特性,官方建议需要在代码中将preg_replace()替换为函数preg_replace_callback,可以问题解决. 具体请见 ...

随机推荐

  1. jumpserver手动配置文档

    1.环境  centos7.6   硬盘 200G  cpu  8核心  内存 32G (本地测试的时候,有报错,原因为虚拟机配置不够,此时为在pve虚拟化上面做的linux系统) 2.https:/ ...

  2. SciPy 信号处理

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  3. 织梦 dede runphp=yes SQL语句操作

    个人实例dede:channelartlist 下循环出 channel 栏目 中的 文章 {dede:sql sql='select * from dede_arctype where reid = ...

  4. 在线关闭 CLOSE_WAIT状态TCP连接

    1.查看某个端口的所有TCP连接: [root@Centos projects]# netstat -anp | tcp6 ::: :::* LISTEN /java tcp6 CLOSE_WAIT ...

  5. python操作mongoDB(pymongo的使用)

    pymongo操作手册 连接数据库 方法一(推荐) import pymongo client = pymongo.MongoClient(host="localhost",por ...

  6. 虚拟机安装安全狗apache服务的一些问题解决方式(11.5)

    首先本文鸣谢bonga的解答大部分问题=.= 由于本人比较懒所以还是喜欢问,不喜欢查啦 1.windows网站安全狗分为:IIS  和  APACHE  版本    我下载的是APACHE版本 (因为 ...

  7. P1087 有多少不同的值

    P1087 有多少不同的值 转跳点:

  8. Aop配置时候的一些问题

    编写切面,并在ApplicationContest.xml 中相关AOP及切面的配置完全正确的情况下,运行报错如下: Exception in thread "main" org. ...

  9. Android的事件处理机制之基于回调的事件处理

    回调机制 如果说事件监听机制是一种委托式的事件处理,那么回调机制则与之相反,对于基于回调的事件处理模型来说,事件源与事件监听器是统一的,换种方法说事件监听器完全消失了,当用户在GUI组件上激发某个事件 ...

  10. 云时代架构阅读笔记十五——之前碰到的Java面试题

    1.一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致. 2.Java有 ...