QtHPConnect/eventthread.cpp

53 lines
1 KiB
C++
Raw Normal View History

2019-03-09 15:39:38 +01:00
#include "eventthread.h"
#include "mainwindow.h"
EventThread::EventThread(MainWindow * parent)
{
main=parent;
if (main)
hpapi=main->getAPI();
}
2019-09-21 18:00:43 +02:00
void EventThread::timerAction()
2019-03-09 15:39:38 +01:00
{
2019-09-21 18:00:43 +02:00
QMutexLocker locker(&mutex);
// qDebug()<<"In Eventhandler";
// QThread::msleep(1);
2019-03-09 15:39:38 +01:00
if(hpapi) {
hpapi->eventHandler();
}
}
void EventThread::start() {
2019-09-15 17:23:44 +02:00
timer = new QTimer(this);
2019-03-09 15:39:38 +01:00
timer->setInterval(100);
2019-09-21 18:00:43 +02:00
// timer->callOnTimeout(SLOT(timerEvent()),Qt::AutoConnection);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(timerAction()),Qt::AutoConnection);
2019-09-15 17:23:44 +02:00
timer->connect(this, SIGNAL(stop()), this, SLOT(stopTimer()));
2019-03-09 15:39:38 +01:00
timer->start();
2019-09-21 18:00:43 +02:00
qDebug()<<"EventThread::started Timer";
2019-03-09 15:39:38 +01:00
}
2019-09-15 17:23:44 +02:00
void EventThread::exit() {
2019-09-21 18:00:43 +02:00
emit stop();
2019-09-15 17:23:44 +02:00
stop();
}
void EventThread::stopTimer() {
2019-09-21 18:00:43 +02:00
qDebug()<<"EventThread::stop Timer";
2019-09-15 17:23:44 +02:00
timer->stop();
2019-09-21 18:00:43 +02:00
emit stopped();
2019-09-15 17:23:44 +02:00
}
EventThread::~EventThread()
{
2019-09-21 18:00:43 +02:00
stopTimer();
2019-09-15 17:23:44 +02:00
if (timer!=nullptr) {
delete timer;
timer=nullptr;
}
qDebug()<<"delete eventThread";
}