{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
public slots:
void update_detection_lb();
void Streaming();
private:
Ui::MainWindow *ui;
// UHD backround worker thread
workerThread *backgroundWorker;
};
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
backgroundWorker = NULL;
backgroundWorker = new workerThread;
//Setup callback for cleanup when it finishes
connect(backgroundWorker, SIGNAL(finished()), backgroundWorker, SLOT(deleteLater()));
// Setup signal slot connections
connect(ui->StartStopStreaming_pb, SIGNAL(clicked()), this, SLOT(Streaming()));
connect(backgroundWorker, SIGNAL(FrameReady()), this, SLOT(update_detection_lb()));
}
void MainWindow::Streaming()
{
if(ui->StartStopStreaming_pb->text() == "Start streaming")
{
ui->StartStopStreaming_pb->setText("Stop streaming");
if(backgroundWorker == NULL)
{
backgroundWorker = new workerThread;
connect(backgroundWorker, SIGNAL(finished()), backgroundWorker, SLOT(deleteLater()));
connect(backgroundWorker, SIGNAL(FrameReady()), this, SLOT(update_detection_lb()));
}
backgroundWorker
->start
(QThread::HighestPriority);
std::cout << "Start streaming in background thread" << std::endl;
}
else{
ui->StartStopStreaming_pb->setText("Start streaming");
backgroundWorker->requestInterruption();
if(!backgroundWorker->wait(5000))
{
std::cout << boost::format("Thread deadlock detected, bad things may happen!") << std::endl;
backgroundWorker->quit();
backgroundWorker->wait();
}
std::cout << "Stop streaming and terminate background thread" << std::endl;
delete backgroundWorker;
}
}