Qt 信号和槽的参数类型,const 引用限定符重要吗? [英] Argument type for Qt signal and slot, does const reference qualifiers matters?
问题描述
对于以下类型的信号和槽
For signal and slot of below type
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 &)));
当信号或插槽中使用不兼容的类型时,我没有注意到输出窗口显示错误消息.我认为信号槽机制能够在编译时检测参数类型错误.
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屋!