QObject :: connect:不能排队类型'int&'的参数 [英] QObject::connect: Cannot queue arguments of type 'int&'

查看:115
本文介绍了QObject :: connect:不能排队类型'int&'的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试这样做:

connect(this, SIGNAL(signalClicked(int&)),  classA, SLOT(doWork(int&)));

但我收到标题中的消息。
所以我探索了互联网,我想出了这个不工作的解决方案:

But I get the message in the title. So I've explored the internet and I came up with this solution which is not working aswell:

 qRegisterMetaType<int&>("Type");
 connect(this, SIGNAL(signalClicked(Type)),  classA, SLOT(doWork(Type)));

(错误:没有匹配函数调用'qRegisterMetaType(const char [5])')

(Error : no matching function for call to ‘qRegisterMetaType(const char[5])’)

任何解决方案?
感谢您的帮助。

Any solutions ? Thanks for your help.

推荐答案

如果Qt正在尝试排队参数,意味着连接在线程。这不适用于非const引用。

If Qt is trying to queue the arguments that means that the connection is between threads. This will not work for non-const references.

您可以使用reference_wrapper解决这个问题,但我强烈建议您重新考虑您的设计。在信号/槽连接中传递参考值不是一个好主意。

You could use a reference_wrapper to work around this, but I would strongly suggest that you reconsider your design. Passing values by reference in signal/slot connections is not a good idea.

这篇关于QObject :: connect:不能排队类型'int&amp;'的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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