今天参考 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. P1068 万绿丛中一点红

    P1068 万绿丛中一点红 转跳点:

  2. Redis Cluster 强制kill某一个节点和shutdown某一个节点后修复过程

    redis cluster 命令行,执行以下命令需登录cluster,是集群所独有的集群(cluster)CLUSTER INFO 打印集群的信息CLUSTER NODES 列出集群当前已知的所有节点 ...

  3. pandas包 —— drop()、sort_values()、drop_duplicates()

    一.drop() 函数 当你要删除某一行或者某一列时,用drop函数,它不改变原有的df中的数据,而是返回另一个dataframe来存放删除后的数据. 1.命令: df.drop() 删除行:df.d ...

  4. Dubbo的配置过程,实现原理及架构详解

    一. Dubbo是什么?Dubbo能做什么? 随着互联网的发展,市场需求快速变更,业务持续高速增长,网站早已从单一应用架构演变为分布式服务架构及流动计算架构.在分布式架构的背景下,在本地调用非本进程内 ...

  5. lvs负载均衡配置

    三台server的ip     direct_server:192.168.248.128     real_server1:192.168.248.130     real_server2:192. ...

  6. Python 常用的标准库以及第三方库有哪些?

    作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  7. PIP无法使用,script文件夹为空解决

    [问题]环境变量已配置,但pip.pip3无法使用,且script文件夹为空解决: 一.安装pip3 python -m ensurepip 运行完之后就pip3有了: 二.安装pip python ...

  8. redis简单的实现(java)

    1.首先新建一个maven项目,在pom.xml中添加依赖 <dependency> <groupId>redis.clients</groupId> <ar ...

  9. 软件管理-RPM命令管理:安装升级与卸载

    1.包名与包全名 包名 : 操作已经安装的软件包时,使用包名:系统会搜索var/lib/rpm中的数据库 包全名: 操作的包时没有安装的软件包时,使用包全名,而且注意路径 2.RPM安装 切换到光盘p ...

  10. 【docker】docker持续集成CI/持续部署CD

    持续集成(CI) 持续集成(Continuous integration)是一种流行的软件开发实践.集成是指开发将自己本地的代码提交到git等远端仓库上,那么持续集成就是每天多次提交,提早提交代码. ...