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.