{
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;
}
}
class MainWindow : public QMainWindow
{
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) :
QMainWindow(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;
}
}
To copy to clipboard, switch view to plain text mode
class workerThread
: public QThread{
Q_OBJECT
public:
workerThread();
~workerThread();
protected:
void run();
signals:
void finished();
void FrameReady();
private:
// UHD member
uhd::usrp::multi_usrp::sptr usrp;
uhd::rx_streamer::sptr rx_stream;
};
workerThread::workerThread()
{
std::cout << "Thread created" << std::endl;
}
workerThread::~workerThread()
{
}
void workerThread::run()
{
std::cout << "Thread running" << std::endl;
while(!this->isInterruptionRequested())
{
// Do streaming stuff
emit FrameReady();
}
std::cout << "Thread terminated" << std::endl;
emit finished();
}
class workerThread : public QThread
{
Q_OBJECT
public:
workerThread();
~workerThread();
protected:
void run();
signals:
void finished();
void FrameReady();
private:
// UHD member
uhd::usrp::multi_usrp::sptr usrp;
uhd::rx_streamer::sptr rx_stream;
};
workerThread::workerThread()
{
std::cout << "Thread created" << std::endl;
}
workerThread::~workerThread()
{
}
void workerThread::run()
{
std::cout << "Thread running" << std::endl;
while(!this->isInterruptionRequested())
{
// Do streaming stuff
emit FrameReady();
}
std::cout << "Thread terminated" << std::endl;
emit finished();
}
To copy to clipboard, switch view to plain text mode
Bookmarks