use thread

This commit is contained in:
hm
2019-12-30 14:09:14 +08:00
parent a550735eb9
commit 61d3d97bea
6 changed files with 75 additions and 31 deletions
+48 -15
View File
@@ -2,29 +2,62 @@
MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
{
this->run();
Nodethread = new QThread();
this->moveToThread(Nodethread);
Nodethread->start();
connect(Nodethread, &QThread::started, this, &MavLinkNode::process);
connect(Nodethread, &QThread::finished, this, &QObject::deleteLater);
qDebug() << "MavLink " << QThread::currentThreadId();
}
int MavLinkNode::run()//线程函数
MavLinkNode::~MavLinkNode()
{
while(1)
{
qDebug() << "run 1ms";
QThread::sleep(1);
}
return 0;
if(Nodethread->isRunning())
{
Nodethread->quit();
Nodethread->wait();
}
}
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
void MavLinkNode::process()//线程函数
{
uint8_t count = 0;
while (1) {
qDebug() << "Process " << QThread::currentThreadId();
count ++;
qDebug() << "run 1ms" << count;
QThread::msleep(1000);
}
}
/*
void MavLinkNode::start()//线程函数
{
qDebug() << "run 1ms";
QThread::msleep(1000);
}
*/