use thread
This commit is contained in:
@@ -58,6 +58,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
this,SLOT(dlink_triggered()));
|
this,SLOT(dlink_triggered()));
|
||||||
|
|
||||||
|
|
||||||
|
MavLinkNode *node = new MavLinkNode();
|
||||||
|
|
||||||
|
|
||||||
|
qDebug() << "mainwindow " << QThread::currentThreadId();
|
||||||
//this->layout()->addWidget(connectpush);
|
//this->layout()->addWidget(connectpush);
|
||||||
//this->layout()->addWidget(disconnectpush);
|
//this->layout()->addWidget(disconnectpush);
|
||||||
//this->setLayout(layout);
|
//this->setLayout(layout);
|
||||||
|
|||||||
+2
-1
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "mavlinknode.h"
|
#include "mavlinknode.h"
|
||||||
|
|
||||||
|
#include "QThread"
|
||||||
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
@@ -35,6 +35,7 @@ protected:
|
|||||||
Cockpit *copk;
|
Cockpit *copk;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
+5
-5
@@ -230,16 +230,16 @@ void Cockpit::paintEvent(QPaintEvent *)
|
|||||||
painter.scale(side / 2000.0, side / 2000.0); /* 比例缩放 */
|
painter.scale(side / 2000.0, side / 2000.0); /* 比例缩放 */
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
drawAttitude(&painter);
|
//drawAttitude(&painter);
|
||||||
drawYawScale(&painter);
|
//drawYawScale(&painter);
|
||||||
drawScale(&painter);
|
//drawScale(&painter);
|
||||||
drawCenterLine(&painter);
|
//drawCenterLine(&painter);
|
||||||
//drawText(&painter);
|
//drawText(&painter);
|
||||||
//drawGPS(&painter);
|
//drawGPS(&painter);
|
||||||
//drawHight(&painter);
|
//drawHight(&painter);
|
||||||
//drawSpeed(&painter);
|
//drawSpeed(&painter);
|
||||||
//drawBattery(&painter);
|
//drawBattery(&painter);
|
||||||
drawLed(&painter);
|
//drawLed(&painter);
|
||||||
//drawProtect(&painter);
|
//drawProtect(&painter);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
|
|
||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
SUBDIRS += App
|
|
||||||
SUBDIRS += SerialPortDialog
|
|
||||||
SUBDIRS += ClientLinkDialog
|
|
||||||
SUBDIRS += Skin
|
|
||||||
|
|
||||||
SUBDIRS += qnavigationwidget
|
CONFIG += ordered
|
||||||
|
|
||||||
SUBDIRS += Cockpit
|
|
||||||
|
|
||||||
|
|
||||||
SUBDIRS += MavLinkNode
|
SUBDIRS += MavLinkNode
|
||||||
|
SUBDIRS += SerialPortDialog
|
||||||
|
SUBDIRS += ClientLinkDialog
|
||||||
|
SUBDIRS += Skin
|
||||||
|
SUBDIRS += qnavigationwidget
|
||||||
|
SUBDIRS += Cockpit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SUBDIRS += App
|
||||||
|
|||||||
+48
-15
@@ -2,29 +2,62 @@
|
|||||||
|
|
||||||
MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MavLinkNode::~MavLinkNode()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int MavLinkNode::run()//线程函数
|
|
||||||
{
|
{
|
||||||
while(1)
|
if(Nodethread->isRunning())
|
||||||
{
|
{
|
||||||
qDebug() << "run 1ms";
|
Nodethread->quit();
|
||||||
QThread::sleep(1);
|
Nodethread->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,20 +12,20 @@ class MavLinkNode : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit MavLinkNode(QObject *parent = nullptr);
|
explicit MavLinkNode(QObject *parent = nullptr);
|
||||||
|
~MavLinkNode();
|
||||||
|
|
||||||
|
|
||||||
|
//void start();
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void process();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int run();
|
|
||||||
|
|
||||||
|
|
||||||
|
QThread *Nodethread;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user