Qt信号和槽的参数类型,const引用限定符有问题吗? [英] Argument type for Qt signal and slot, does const reference qualifiers matters?

查看:1784
本文介绍了Qt信号和槽的参数类型,const引用限定符有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于

signals:
    void textChanged(const QString &);

public slots:
    void setText(const QString & text)

textChanged和setText的参数类型似乎无法修改 const & 。与仅使用QString相比,常量和引用限定是否有什么区别?

the type of argument of textChanged and setText seems to work invarable of const and &. Does the constant and reference qualification make any difference compared to just using QString ?

QObject::connect(a,SIGNAL(textChanged(QString)),b,SLOT(setText(QString)));
QObject::connect(a,SIGNAL(textChanged(const QString &)),b,SLOT(setText(const QString &)));

编辑:
当没有不兼容类型时,我没有注意到显示错误消息的输出窗口用于SIGNAL或SLOT。我认为信号槽机制能够在编译时检测参数类型错误。

I did not notice the output window showing error messages when there is incompatible type being used in SIGNAL or SLOT. I thought the signal slot mechanism is capable of detecting argument type error at compile time.

推荐答案

Qt检查正规化签名,意味着


标准化将空格减少到
,将const移动到前面
在适当的情况下,从值类型中删除'const'
,并替换const
带有值的引用。

Normalization reduces whitespace to a minimum, moves 'const' to the front where appropriate, removes 'const' from value types and replaces const references with values.

这篇关于Qt信号和槽的参数类型,const引用限定符有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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