完善指令接口,但是qml界面突然会卡,不知道什么情况
This commit is contained in:
+4
-8
@@ -2,7 +2,6 @@ import QtQuick 2.6
|
||||
import QtQuick.Controls 2.5
|
||||
|
||||
//导入指令模块,这样就能发指令了
|
||||
//import Drivers.LinkUI 1.0
|
||||
import CommandMsg 1.0
|
||||
|
||||
|
||||
@@ -17,15 +16,11 @@ Rectangle {
|
||||
border.color: "blue"
|
||||
color: "white"
|
||||
|
||||
signal btnclicked_int(real param1, real param2, real param3, real param4, int x, int y, real z)
|
||||
signal btnclicked_long(real param1, real param2, real param3, real param4, real param5, real param6, real param7)
|
||||
|
||||
CommandMsg {
|
||||
objectName: 'GetInfo'
|
||||
CommandMsg {//如果用于多个这个块,那么就会发送多次指令
|
||||
objectName: 'CommandInterface'
|
||||
id: data
|
||||
}
|
||||
|
||||
|
||||
Rectangle {
|
||||
id:armbtn
|
||||
x:10
|
||||
@@ -69,8 +64,9 @@ Rectangle {
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
btnclicked_int(0,0,0,0,0,0,0)
|
||||
data.text = "ARM"
|
||||
data.btnclicked_int(0,0,0,0,0,0,0)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,30 @@ void CommandMsg::setText(const QString &text)
|
||||
|
||||
|
||||
|
||||
void CommandMsg::btnclicked_int(float param1, float param2, float param3, float param4, int x, int y, float z)
|
||||
{
|
||||
qDebug() << param1
|
||||
<< param2
|
||||
<< param3
|
||||
<< param4
|
||||
<< x
|
||||
<< y
|
||||
<< z;
|
||||
emit cmd_int(param1,param2,param3,param4,x,y,z);
|
||||
|
||||
}
|
||||
void CommandMsg::btnclicked_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7)
|
||||
{
|
||||
qDebug() << param1
|
||||
<< param2
|
||||
<< param3
|
||||
<< param4
|
||||
<< param5
|
||||
<< param6
|
||||
<< param7;
|
||||
emit cmd_long(param1,param2,param3,param4,param5,param6,param7);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define COMMANDMSG_H
|
||||
|
||||
#include <QObject>
|
||||
#include "QDebug"
|
||||
|
||||
class CommandMsg : public QObject
|
||||
{
|
||||
@@ -13,9 +14,26 @@ public:
|
||||
QString text() const;
|
||||
void setText(const QString &text);
|
||||
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
void btnclicked_int(float param1, float param2, float param3, float param4, int x, int y, float z);
|
||||
void btnclicked_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
void textChanged(QString str);
|
||||
|
||||
|
||||
void cmd_int(float param1, float param2, float param3, float param4, int x, int y, float z);
|
||||
void cmd_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
|
||||
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
RegisterType();
|
||||
|
||||
w.setWindowTitle(QStringLiteral("GCS New Frame @ %1"));//with version
|
||||
w.setWindowTitle(QString("GCS New Frame by Qt%1").arg(QT_VERSION_STR));//with version
|
||||
// 主要是控制HDMI输出,如果是LCD显示,此行无关紧要
|
||||
w.resize(GetDesktopSize());
|
||||
|
||||
|
||||
+20
-47
@@ -71,9 +71,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
copk->setGeometry(this->width() - copk->width(),0,300,340);
|
||||
|
||||
|
||||
//作为一个位于本工程的类,是可以注册的
|
||||
//在quick load 之前注册即可
|
||||
qmlRegisterType<CommandMsg>("CommandMsg", 1, 0, "CommandMsg");
|
||||
|
||||
|
||||
quick = new QQuickWidget(this);
|
||||
quick->setFocus();
|
||||
quick->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
@@ -87,23 +88,25 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
QObject *pRoot = (QObject*)quick->rootObject();
|
||||
const QObjectList list = pRoot->children();
|
||||
|
||||
/* 这一段可以读取qml底下的第n个对象,例如CommandMsg位于第0个,所有读取第0个对象连接 */
|
||||
m_data = static_cast<CommandMsg*>(list[0]);
|
||||
qDebug() << list[0]->metaObject()->className();
|
||||
qDebug() << list[0]->objectName();
|
||||
connect(m_data, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
|
||||
|
||||
foreach(QObject *Item,list)//查找 CommandMsg 类,然后连接
|
||||
{
|
||||
|
||||
if((QString)Item->metaObject()->className() == "CommandMsg")//找到 CommandMsg 类
|
||||
{
|
||||
qDebug() << Item->metaObject()->className() << Item->objectName();
|
||||
m_Command = static_cast<CommandMsg*>(Item);
|
||||
connect(m_Command,SIGNAL(cmd_int(float,float,float,float,int,int,float)),
|
||||
dlink->mavlinknode->Commander,SLOT(_int(float,float,float,float,int32_t,int32_t,float,uint16_t,uint8_t,uint8_t,uint8_t)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//刷新ui,以保证界面不卡
|
||||
QTimer::singleShot(200,this,&MainWindow::updateUI);
|
||||
|
||||
|
||||
updateTimer = new QTimer();
|
||||
|
||||
connect(updateTimer,&QTimer::timeout,
|
||||
this,&MainWindow::updateUI);
|
||||
|
||||
updateTimer->start(200);
|
||||
|
||||
//=======信号和槽========
|
||||
connect(linkui,&LinkUI::clicked,
|
||||
this,&MainWindow::subui);
|
||||
@@ -114,26 +117,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(toolsui,&ToolsUI::clicked,
|
||||
this,&MainWindow::subui);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::textChanged(const QString &str)
|
||||
{
|
||||
QString currentData = QDateTime::currentDateTime().toString("hh:mm:ss") + " ";
|
||||
currentData.append(str);
|
||||
qDebug() << currentData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
@@ -161,27 +146,13 @@ void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
this->width()- copk->width() - nav->width(),
|
||||
this->height());
|
||||
|
||||
/*
|
||||
map->setGeometry(0,
|
||||
0,
|
||||
this->width()- copk->width(),
|
||||
this->height());
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
map->setGeometry(0,
|
||||
0,
|
||||
this->width(),
|
||||
this->height());
|
||||
*/
|
||||
|
||||
|
||||
nav->setGeometry(0,0,nav->width(),this->height());
|
||||
copk->setGeometry(this->width() - copk->width(),0,copk->width(),copk->height());
|
||||
quick->setGeometry(this->width() - quick->width(),copk->height(),quick->width(),this->height() - copk->height());
|
||||
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -425,6 +396,8 @@ void MainWindow::updateUI()//事件驱动式更新数据
|
||||
copk->setAltitude(dlink->mavlinknode->vehicle.gps_raw_int.alt * 10e-3 );
|
||||
copk->setAirSpeed(dlink->mavlinknode->vehicle.airspeed_autocal.vx);
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-4
@@ -20,7 +20,6 @@
|
||||
#include "clientlinkdialog.h"
|
||||
#include "mavlinknode.h"
|
||||
|
||||
|
||||
//ui include
|
||||
#include "LinkUI/LinkUI.h"
|
||||
#include "InspectUI/InspectUI.h"
|
||||
@@ -86,8 +85,6 @@ private slots:
|
||||
|
||||
|
||||
protected slots:
|
||||
void textChanged(const QString &str);
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
@@ -116,7 +113,7 @@ protected:
|
||||
QTimer *updateTimer;
|
||||
|
||||
|
||||
CommandMsg *m_data;
|
||||
CommandMsg *m_Command;
|
||||
|
||||
|
||||
};
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ int DLink::SendMessageTo(quint8 ch, quint8 *msg, quint16 len)
|
||||
if (DLink::serialPort)
|
||||
{
|
||||
DLink::serialPort->write((const char *)msg,len);
|
||||
//qDebug() << "serialPort Send Msg" << msg;
|
||||
qDebug() << "serialPort Send Msg" << msg;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user