use thread
This commit is contained in:
+48
-15
@@ -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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user