我有一串实时数据来自于一个生产者对象所处理的硬件。 这将会连接到一个消费者,以在其自己的线程中处理它,以保持GUI响应。
mainwindow::startProcessing(){
QObject::connect(producer,SIGNAL(dataReady(data*),consumer,SLOT(doData(data*)));
consumer->moveToThread(&consumerThread);
consumerThread.start();
}
mainwindow::stopProcessing(){
producer->disconnect(SIGNAL(dataReady(data*));
consumer->cleanup();
delete consumer;
}
consumer::doData(data* x) {
mutex.lock();
processingObject stuff
mutex.unlock()
}
consumer::cleanup() {
mutex.tryLock();
.... blah ....
delete processingObject; // then doData gets called again
}
我的问题是,在销毁消费者对象后,即使进行了断开连接,我仍然会收到发往该对象的信号。我尝试了越来越复杂的互斥锁来阻止这种情况,但理想的解决方案是清理等待所有未处理的信号被处理完毕。
有没有办法监视排队等待槽的未处理信号数量?或者有没有方法清除它们?