跪求qt开发GPS相关参考资料
答案:1 悬赏:20 手机版
解决时间 2021-11-10 18:41
- 提问者网友:沉默的哀伤
- 2021-11-10 07:52
跪求qt开发GPS相关参考资料
最佳答案
- 五星知识达人网友:夜余生
- 2021-11-10 08:56
已将全部源代码发至您邮箱,下面是主窗口的源代码。
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
updatingGps(false)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openGps()
{
myGpsCom =new Win_QextSerialPort("COM1",QextSerialBase::Polling);
//初始化com1端口
if(myGpsCom->open(QIODevice::ReadOnly))
ui->statusBar->showMessage(tr("open com1 success!!!"),2000);
else{
ui->statusBar->showMessage(tr("open com1 failed!!!"),2000);
return;
}
myGpsCom->setBaudRate(BAUD9600); //波特率设置,我们设置为115200
myGpsCom->setDataBits(DATA_8); //数据为设置,我们设置为8位数据位。
myGpsCom->setParity(PAR_NONE); //奇偶校验设置 为无
myGpsCom->setStopBits(STOP_1); //设置一位停止位
myGpsCom->setFlowControl(FLOW_OFF); //数据流控制设置,无
myGpsCom->setTimeout(TIME_OUT);//设置延时
readTimer = new QTimer(this);//创建一个定时器
readTimer->start(TIME_INTERVAL);
QObject::connect(readTimer,SIGNAL(timeout()),this,SLOT(readGpsDate()));
}
void MainWindow::GpsDisplay()
{
QString str;
if(updatingGps)
{
ui->altitudeDisplay->setText(Gps_list[3]+" "+Gps_list[4]);;
ui->longtitudeDisplay->setText(Gps_list[5]+" "+Gps_list[6]);
ui->speedDisplay->setText(Gps_list[7]);
ui->dateDisplay->setText(Gps_list[9]+" UTC");
ui->statusDisplay->setText(Gps_list[2]);
ui->timeDisplay->setText(Gps_list[1]+" UTC");
}
Gps_list.clear();
}
void MainWindow::readGpsDate()
{
int newGpsMsg;
if(updatingGps)
newGpsMsg = myGpsCom->bytesAvailable();
if(newGpsMsg)
ui->statusBar->showMessage(tr("Accepting data!!!"),1000);
else{
ui->statusBar->showMessage(tr("Time Delay or No data!"),1000);
return;//没有数据,就返回
}
QByteArray GPS_Data;
GPS_Data+= myGpsCom->readAll();//read(newGpsMsg);//读串口GPS信息
if(GPS_Data.contains("$GPRMC"))//读取RMC语句
{
GPS_Data.remove(0,GPS_Data.indexOf("$GPRMC"));
if(GPS_Data.contains("*"))
{
QByteArray GPS_RMC = GPS_Data.left(GPS_Data.indexOf("*"));
//获得,$GPRMC 句子的定位信息
Gps_list.clear();
Gps_list << GPS_RMC.split(',');
//提取分隔符之间的信息,存入容器列表
ui->statusBar->showMessage(tr("accept Gps Data in Gps_list"),1000);
GpsDisplay();
}
}
}
void MainWindow::on_StartGPSBtn_clicked()
{
if(!updatingGps)
{
updatingGps=true;
openGps();
}
ui->statusBar->showMessage(tr("GPS STARTED!"),1000);
}
void MainWindow::on_StopGPSBtn_clicked()
{
if(updatingGps)
{
myGpsCom->close();
delete myGpsCom;
readTimer->stop();
updatingGps=false;
ui->statusDisplay->setText(tr("Stop Working !!!"));
}
ui->statusBar->showMessage(tr("COM1 CLOSED!"),1000);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
updatingGps(false)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openGps()
{
myGpsCom =new Win_QextSerialPort("COM1",QextSerialBase::Polling);
//初始化com1端口
if(myGpsCom->open(QIODevice::ReadOnly))
ui->statusBar->showMessage(tr("open com1 success!!!"),2000);
else{
ui->statusBar->showMessage(tr("open com1 failed!!!"),2000);
return;
}
myGpsCom->setBaudRate(BAUD9600); //波特率设置,我们设置为115200
myGpsCom->setDataBits(DATA_8); //数据为设置,我们设置为8位数据位。
myGpsCom->setParity(PAR_NONE); //奇偶校验设置 为无
myGpsCom->setStopBits(STOP_1); //设置一位停止位
myGpsCom->setFlowControl(FLOW_OFF); //数据流控制设置,无
myGpsCom->setTimeout(TIME_OUT);//设置延时
readTimer = new QTimer(this);//创建一个定时器
readTimer->start(TIME_INTERVAL);
QObject::connect(readTimer,SIGNAL(timeout()),this,SLOT(readGpsDate()));
}
void MainWindow::GpsDisplay()
{
QString str;
if(updatingGps)
{
ui->altitudeDisplay->setText(Gps_list[3]+" "+Gps_list[4]);;
ui->longtitudeDisplay->setText(Gps_list[5]+" "+Gps_list[6]);
ui->speedDisplay->setText(Gps_list[7]);
ui->dateDisplay->setText(Gps_list[9]+" UTC");
ui->statusDisplay->setText(Gps_list[2]);
ui->timeDisplay->setText(Gps_list[1]+" UTC");
}
Gps_list.clear();
}
void MainWindow::readGpsDate()
{
int newGpsMsg;
if(updatingGps)
newGpsMsg = myGpsCom->bytesAvailable();
if(newGpsMsg)
ui->statusBar->showMessage(tr("Accepting data!!!"),1000);
else{
ui->statusBar->showMessage(tr("Time Delay or No data!"),1000);
return;//没有数据,就返回
}
QByteArray GPS_Data;
GPS_Data+= myGpsCom->readAll();//read(newGpsMsg);//读串口GPS信息
if(GPS_Data.contains("$GPRMC"))//读取RMC语句
{
GPS_Data.remove(0,GPS_Data.indexOf("$GPRMC"));
if(GPS_Data.contains("*"))
{
QByteArray GPS_RMC = GPS_Data.left(GPS_Data.indexOf("*"));
//获得,$GPRMC 句子的定位信息
Gps_list.clear();
Gps_list << GPS_RMC.split(',');
//提取分隔符之间的信息,存入容器列表
ui->statusBar->showMessage(tr("accept Gps Data in Gps_list"),1000);
GpsDisplay();
}
}
}
void MainWindow::on_StartGPSBtn_clicked()
{
if(!updatingGps)
{
updatingGps=true;
openGps();
}
ui->statusBar->showMessage(tr("GPS STARTED!"),1000);
}
void MainWindow::on_StopGPSBtn_clicked()
{
if(updatingGps)
{
myGpsCom->close();
delete myGpsCom;
readTimer->stop();
updatingGps=false;
ui->statusDisplay->setText(tr("Stop Working !!!"));
}
ui->statusBar->showMessage(tr("COM1 CLOSED!"),1000);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯