use thread
This commit is contained in:
@@ -58,6 +58,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
this,SLOT(dlink_triggered()));
|
||||
|
||||
|
||||
MavLinkNode *node = new MavLinkNode();
|
||||
|
||||
|
||||
qDebug() << "mainwindow " << QThread::currentThreadId();
|
||||
//this->layout()->addWidget(connectpush);
|
||||
//this->layout()->addWidget(disconnectpush);
|
||||
//this->setLayout(layout);
|
||||
|
||||
+2
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "mavlinknode.h"
|
||||
|
||||
|
||||
#include "QThread"
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
@@ -35,6 +35,7 @@ protected:
|
||||
Cockpit *copk;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
+5
-5
@@ -230,16 +230,16 @@ void Cockpit::paintEvent(QPaintEvent *)
|
||||
painter.scale(side / 2000.0, side / 2000.0); /* 比例缩放 */
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
drawAttitude(&painter);
|
||||
drawYawScale(&painter);
|
||||
drawScale(&painter);
|
||||
drawCenterLine(&painter);
|
||||
//drawAttitude(&painter);
|
||||
//drawYawScale(&painter);
|
||||
//drawScale(&painter);
|
||||
//drawCenterLine(&painter);
|
||||
//drawText(&painter);
|
||||
//drawGPS(&painter);
|
||||
//drawHight(&painter);
|
||||
//drawSpeed(&painter);
|
||||
//drawBattery(&painter);
|
||||
drawLed(&painter);
|
||||
//drawLed(&painter);
|
||||
//drawProtect(&painter);
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += App
|
||||
SUBDIRS += SerialPortDialog
|
||||
SUBDIRS += ClientLinkDialog
|
||||
SUBDIRS += Skin
|
||||
|
||||
SUBDIRS += qnavigationwidget
|
||||
CONFIG += ordered
|
||||
|
||||
SUBDIRS += Cockpit
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,20 +12,20 @@ class MavLinkNode : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MavLinkNode(QObject *parent = nullptr);
|
||||
~MavLinkNode();
|
||||
|
||||
|
||||
|
||||
|
||||
//void start();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void process();
|
||||
|
||||
protected:
|
||||
int run();
|
||||
|
||||
|
||||
QThread *Nodethread;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user