Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

qthread

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 either:

 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?

like image 500
Thibel Avatar asked Jun 13 '13 09:06

Thibel


1 Answers

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.

like image 147
Dan Milburn Avatar answered Nov 05 '22 16:11

Dan Milburn