Qt的信号和槽参数类型,确实常引用预选赛事项? [英] Argument type for Qt signal and slot, does const reference qualifiers matters?

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

问题描述

有关信号及以下类型的插槽

For signal and slot of below type

signals:
    void textChanged(const QString &);

public slots:
    void setText(const QString & text)

框TextChanged和的setText的参数的类型似乎工作的常量&放invarable; 。是否常和参考资格作出任何差别相比,只是使用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 &)));

编辑:
我没有注意到输出窗口显示错误信息时,有信号或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的检查一个标准化签名 ,这意味着

Qt checks a normalized signature, meaning

正常化减少空白到
  最小,移动'常量'前线
  在适当情况下,删除'常量'
  从值类型和常量替换
  其值引用。

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的信号和槽参数类型,确实常引用预选赛事项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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