1.GPS型号为ublox(EVK-M8L),配有USB接口,Qt版本5.7

2.实现步骤:

(1)实现串口通信

  采用Qt5.7 内置的串口操作类QSerialPort和QSerialPortInfo,通过QSerialPortInfo提供的函数availablePorts(),可枚举出当前计算机中可用的com口。使用该类需在pro文件中添加:

QT += serialport

(2)筛选感兴趣的信号,解析

  GPRMC数据包基本上包含经纬度、航向角、时间等常用的信号。

3.效果图

4.源码

4.1 头文件

 #ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
~MainWindow(); public:
QSerialPort serial;//串口实例
void initSeialPort();//初始化串口函数
private:
void gpsParse(QByteArray GPSBuffer);//gps解析函数 private slots:
void serialRead(); void on_connectBtn_clicked(); void on_closeBtn_clicked(); private:
Ui::MainWindow *ui;
}; #endif // MAINWINDOW_H

4.2实现文件

 #include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include <QList> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStringList strBaud;
strBaud<<""<<""<<"";
ui->baudcomboBox->addItems(strBaud); initSeialPort();
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::initSeialPort()
{
connect(&serial,SIGNAL(readyRead()),this,SLOT(serialRead())); //连接槽 //获取计算机上所有可用串口并添加到comboBox中
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
if(infos.isEmpty())
{
ui->portcomboBox->addItem("无串口");
return;
}
foreach (QSerialPortInfo info, infos) {
ui->portcomboBox->addItem(info.portName());
qDebug() << info.portName();
} } void MainWindow::serialRead()
{
QByteArray qa = serial.readAll(); ui->textEdit->append(qa); gpsParse(qa); ui->statusLabel->setText("读取中...");
} void MainWindow::gpsParse(QByteArray GPSBuffer)
{ // qDebug()<<GPSBuffer.size(); if(GPSBuffer.contains("$GNRMC") )
{ QList<QByteArray> gpsByteArrays = GPSBuffer.split(',');
int count = gpsByteArrays.count(); int gpsLat_1 = static_cast<int>(gpsByteArrays.at().toDouble()/);
double gpsLat_2 = (gpsByteArrays.at().toDouble() - gpsLat_1 * )/;
double gpslat=gpsLat_1 + gpsLat_2; int gpsLong_1 = static_cast<int>(gpsByteArrays.at().toDouble()/);
double gpsLong_2 = (gpsByteArrays.at().toDouble()-gpsLong_1 * )/;
double gpsLong = gpsLong_1 + gpsLong_2; ui->timelineEdit->setText(gpsByteArrays.at());
ui->latlineEdit->setText(QString::number(gpslat,'g',));
ui->longlineEdit->setText(QString::number(gpsLong,'g',)); if(!gpsByteArrays.at().isEmpty())
ui->headlineEdit->setText(gpsByteArrays.at()); }
} void MainWindow::on_connectBtn_clicked()
{
QSerialPortInfo info;
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
int i = ;
foreach (info, infos) {
if(info.portName() == ui->portcomboBox->currentText()) break;
i++;
} if(i != infos.size ()){//can find
ui->statusLabel->setText("串口打开成功"); serial.close();
serial.setPort(info);
serial.open(QIODevice::ReadWrite); //读写打开
switch (ui->baudcomboBox->currentIndex()) {
case :
serial.setBaudRate(QSerialPort::Baud4800);
break;
case :
serial.setBaudRate(QSerialPort::Baud9600);
qDebug()<<"";
break;
case :
serial.setBaudRate(QSerialPort::Baud115200);
qDebug()<<"";
default:
break;
} // serial.setBaudRate(QSerialPort::Baud9600); //波特率
// serial.setDataBits(QSerialPort::Data8); //数据位
// serial.setParity(QSerialPort::NoParity); //无奇偶校验
// serial.setStopBits(QSerialPort::OneStop); //无停止位
// serial.setFlowControl(QSerialPort::NoFlowControl); //无控制
}else{
serial.close(); ui->statusLabel->setText("串口打开失败");
}
} void MainWindow::on_closeBtn_clicked()
{
serial.close();
ui->statusLabel->setText("串口断开");
}

Qt - 读取GPS数据的更多相关文章

  1. GPS数据读取与处理

    GPS数据读取与处理 GPS模块简介 SiRF芯片在2004年发布的最新的第三代芯片SiRFstar III(GSW 3.0/3.1),使得民用GPS芯片在性能方面登上了一个顶峰,灵敏度比以前的产品大 ...

  2. Qt读取JSON和XML数据

    QJSON JSON(JavaScript Object Notation)是一个轻量级的数据交换格式; 可以将数据以name/value的形式任意组合; QJson 是一个基于Qt的库, 将JSON ...

  3. Qt通过odbc读取excel数据

    传统的读取方式是通过Excel.Application,这种方式不仅操作繁琐,而且速度也不快. 通过odbc读取,可以使用select语句直接读取整个工作表,处理excel数据就跟数据库一样方便. 当 ...

  4. Qt监控Arduino开关状态(读取串口数据)

    setup.ini配置文件内容 [General] #游戏所在主机IP GameIp1=192.168.1.151 GameIp2=192.168.1.152 GameIp3=192.168.1.15 ...

  5. 采集的GPS数据如何正确显示在arcgis和cad中

    利用GPS定位卫星,在全球范围内实时进行定位.导航的系统,称为全球卫星定位系统,简称GPS.GPS是由美国国防部研制建立的一种具有全方位.全天候.全时段.高精度的卫星导航系统,能为全球用户提供低成本. ...

  6. 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult。InnerException 消息是“反序列化对象 属于类型 lzdt.DTO.Dtolzdt[] 时出现错误。读取 XML 数据时,超出最大

    当遇到这个错误的时候郁闷了好长时间报错是字符串长度过大可是修改了MaxStringContentLength”属性的值却不起作用最后才发现还是因为配置文件配置的问题在服务端 格式化程序尝试对消息反序列 ...

  7. 使用 Qt 获取 UDP 数据并显示成图片(2)

    本文首发于 BriFuture 的 个人博客 在我的前一篇文章 使用 Qt 获取 UDP 数据并显示成图片 中,我讲了如何用 Python 模拟发送数据,如何在 Qt 中高效的接收 UDP 数据包并将 ...

  8. java的poi技术读取Excel数据到MySQL

    这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中. 你也可以在 : java的poi技术读取和导入Excel了解到写入Excel的方法信息 使用JXL技术可以在 ...

  9. Hive读取外表数据时跳过文件行首和行尾

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 有时候用hive读取外表数据时,比如csv这种类型的,需要跳过行首或者行尾一些和数据无关的或者自 ...

随机推荐

  1. MVC系列——MVC源码学习:打造自己的MVC框架(二:附源码)

    前言:上篇介绍了下 MVC5 的核心原理,整篇文章比较偏理论,所以相对比较枯燥.今天就来根据上篇的理论一步一步进行实践,通过自己写的一个简易MVC框架逐步理解,相信通过这一篇的实践,你会对MVC有一个 ...

  2. JS组件系列——BootstrapTable 行内编辑解决方案:x-editable

    前言:之前介绍bootstrapTable组件的时候有提到它的行内编辑功能,只不过为了展示功能,将此一笔带过了,罪过罪过!最近项目里面还是打算将行内编辑用起来,于是再次研究了下x-editable组件 ...

  3. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  4. 【Mysql】 局域网远程连接问题

    设置了 user 表 的 host为‘%’ 为什么局域网还是连接不上: 新建查询-->分别执行 1.GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTI ...

  5. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  6. 【hihocoder#1413】Rikka with String 后缀自动机 + 差分

    搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...

  7. Mysql 修改字段默认值

    环境:MySQL 5.7.13 问题描述:建表的时候,users_info表的role_id字段没有默认值,后期发现注册的时候,需要提供给用户一个默认角色,也就是给role_id字段一个默认值. 当前 ...

  8. xshell有大量打印时,显示信息不全

    使用xshell远程登录ssh时,编译大型工程或在minicom打印嵌入式设备的信息,发现显示不全. 在网上搜索了一下也没有发现有解决办法. 经过实验发现 xshell terminal type设置 ...

  9. crodova打包apk个人总结

    1.安装nodejs 2.安装 cordova npm install -g cordova 3.安装Java JDK,官网下载地址 系统变量→新建 JAVA_HOME 变量 . 变量值填写jdk的安 ...

  10. 添加自编译的apache为linux系统服务

    步骤1添加服务脚本 #cp /app/apache2/bin/apachectl /etc/rc.d/init.d/httpd #ln -s /etc/rc.d/init.d/httpd /etc/r ...