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

I tried to do this:

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

But I get a message in the title. So I studied the internet, and I came up with this solution, which does not work either:

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

(Error: there is no corresponding function to call 'qRegisterMetaType (const char [5]))

Any solutions? Thank you for your help.

+6
source share
1 answer

If Qt tries to queue arguments that mean a connection between threads. This will not work for non-constant links.

You can use reference_wrapper to get around this, but I highly recommend that you rethink your design. Passing values ​​by reference in signal / slot connections is not a good idea.

+11
source

Source: https://habr.com/ru/post/947198/


All Articles