今天参考 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. SciPy 特殊函数

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

  2. python 中常见的异常类型汇总

    异常名称 描述 BaseException 所有异常的基类 SystemExit 解释器请求退出 KeyboardInterrupt 用户中断执行(通常是输入^C) Exception 常规错误的基类 ...

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

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

  4. P1078 字符串压缩与解压

    P1078 字符串压缩与解压 转跳点:

  5. centos 禁用ip v6

    #  sysctl -w net.ipv6.conf.all.disable_ipv6=1 #  sysctl -w net.ipv6.conf.default.disable_ipv6=1 #  s ...

  6. 使用 esxcli storage vmfs unmap 命令在精简置备的 LUN 上回收 VMFS 删除的块

    官方原文链接: https://kb.vmware.com/s/article/2057513?lang=zh_CN 本文介绍如何通过运行 esxcli storage vmfs unmap 命令回收 ...

  7. jenkins#安装docker

    环境:centos7 安装依赖包 yum install -y yum-utils device-mapper-persistent-data lvm2 添加Docker软件包源 yum-config ...

  8. PhoneGap简易配置使用

    在Android Studio 里新一下Android项目, 这个不用说了. 链接: https://pan.baidu.com/s/1qYcCBEW 密码: ymhh 添加 cordovaapp-c ...

  9. 014.Delphi插件之QPlugins,MDI窗口

    不知道为什么,这个DEMO编译出来报错,运行不了,在QDAC群里问了一下也没人响应. 效果如下 主程序代码如下 unit Frm_Main; interface uses Winapi.Windows ...

  10. socket简单调用

    下载 Client using System; using System.Collections.Generic; using System.Linq; using System.Text; //导入 ...