在最近的一个项目中,我通过刮掉一些牦牛“解决”了这个问题,错误,编写了一些路由包装器。
class FooClass : public QThread
{
Q_OBJECT
/* ... */
public slots:
/* to thread loopback signals */
void setBufferCount(
unsigned int buffercount ) {
QMetaObject::invokeMethod(this, "_priv_loslot_setBufferCount",
Qt::QueuedConnection,
Q_ARG(unsigned int, buffercount) );
}
private slots:
/*
* private loopback slots
* ^^^^ ^^ ^^^^
*
* These slots are connected to the coresponding frontend
* signals. Calling a frontend signal will send a invocation
* between the threads, calling the loopback slots within
* the worker thread.
*/
void _priv_loslot_setBufferCount(unsigned int buffercount);
/* ... */
}
通过调用或连接到公共插槽,通过调用Qt::QueuedConnection上的invokeMethod进行内部包装就可以了。