QObject::connect: Cannot queue arguments of type 'int&'

匿名 (未验证) 提交于 2019-12-03 08:44:33

问题:

I tried to do this :

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))); 

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

Any solutions ? Thanks for your help.

回答1:

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

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!