void SignalThread::OnMessage(Message *msg) { EnterExit ee(this); if (ST_MSG_WORKER_DONE == msg->message_id) { ASSERT(main_->IsCurrent()); OnWorkDone(); bool do_delete = false; if (kRunning == state_) { state_ = kComplete; } else { do_delete = true; } if (kStopping != state_) { // Before signaling that the work is done, make sure that the worker // thread actually is done. We got here because DoWork() finished and // Run() posted the ST_MSG_WORKER_DONE message. This means the worker // thread is about to go away anyway, but sometimes it doesn't actually // finish before SignalWorkDone is processed, and for a reusable // SignalThread this makes an assert in thread.cc fire. // // Calling Stop() on the worker ensures that the OS thread that underlies // the worker will finish, and will be set to NULL, enabling us to call // Start() again. worker_.Stop(); SignalWorkDone(this); } if (do_delete) { refcount_--; } } }
void ImageExtractor::InitConnection() { connect(ui.btnBrowseOutputPath, SIGNAL(clicked()), this, SLOT(OnBtnBrowseOutputPathClicked())); connect(ui.btnStart, SIGNAL(clicked()), this, SLOT(OnBtnStartClicked())); connect(ui.cmbTask, SIGNAL(currentIndexChanged(int)), this, SLOT(OnParameterChanged())); connect(ui.btnCustomOutputPath, SIGNAL(clicked()), this, SLOT(OnParameterChanged())); connect(ui.btnExtractFile, SIGNAL(clicked()), this, SLOT(OnParameterChanged())); connect(ui.btnExtractImageFile, SIGNAL(clicked()), this, SLOT(OnParameterChanged())); connect(ui.btnMergeImage, SIGNAL(clicked()), this, SLOT(OnParameterChanged())); m_workThread = new WorkThread; connect(m_workThread, SIGNAL(emitStatus(QString)), this, SLOT(OnEmitWorkStatus(QString))); connect(m_workThread, SIGNAL(emitProcess(int)), this, SLOT(OnEmitWorkProcess(int))); connect(m_workThread, SIGNAL(emitInformation(QString)), this, SLOT(OnEmitWorkInformation(QString))); connect(m_workThread, SIGNAL(finished()), this, SLOT(OnWorkDone())); }