QT:Qt4添加QSerialPort模块
来源:互联网 发布:收购淘宝卖家账号 编辑:程序博客网 时间:2024/06/07 02:08
转自:http://blog.csdn.net/yuyu414/article/details/42400721
Qt中添加了QSerialPort类,非常好用,可是由于各种原因,很多人还是要用Qt4,比如我,后来发现官方文档说QSerialPort支持Qt4,就研究了一下,比较笨,搞了好久才弄好。
第一步:下载QSerialPort模块
官方网站我经常打不开,所以上传到网盘了。
http://download.qt-project.org/这是官方的,各种版本都有,大家可以自己找找。
http://pan.baidu.com/s/1gdnanOv这是我自己下载的,共享给大家。
第二步:打开QSerialPort工程
首先确认您电脑上有可以正常使用的Qt4版本,我这里用的是Qt4.8.6.
解压下载的qtserialport-opensource-src-5.3.2.rar,会发现一个qtserialport.pro,打开它。
选择项目,在构建步骤中选择“添加构建步骤->Make”,如下图:
在Make参数这一栏里输入“install”
搞定,现在点击项目中的“构建”,就会编译,然后把QSerialPort库安装到你的Qt4里面。
这是Debug版本,然后Release版本也是一样做的
第三步:编译错误undefined reference to ...
如果是下载的官方的,可能会有下面的错误:(建议用最新的5.4.2版本,已经修复改错误,后面有链接)
跟踪到错误的地方:
修改为:
再次编译,还有错误:
跟踪错误地方:
修改为:注意四个地方都要修改
第四步:串口测试程序
新建一个工程,在pro文件中加入 CONFIG += serialport
然后在.h文件中包含 #include <QSerialPort/QSerialPort> #include <QSerialPort/QSerialPortInfo>
搞定了,QSerialPortInfo是一个很不错的东西,可以查找电脑上的可用串口,用法如下:
有时候串口比较多的时候,会发现排序混乱,向下面这个样子:
作为一个重度强迫症程序员,这是绝对不允许的,3怎么能排在8后面呢,绝对不能!!!
这样解决:
这回看起来就舒服多了:
差不多就这些了。
虚拟串口工具
推荐一个虚拟串口工具,很好用,里面有教程
http://download.csdn.net/detail/yuyu414/5094469
上面这个需要两个积分,找了半天不知道怎么删掉积分要求,重新上传了一份在百度网盘,好东西,当然要大家来分享
http://pan.baidu.com/s/1o69M78I
——————————————————我是分割线——————————————————
Qt串口模块更新:qtserialport-opensource-src-5.4.0
修复了上面的错误,官方更新日志:
- [QTBUG-41190] Fixed build on Qt4 related to QT_DEPRECATED_SINCE(5, 2) macro.
- QSerialPortInfo:
* Added support of a serial number of the USB device from the Sysfs backend.
* Fixed crash on OSX related to wrong use of QCFString class.
* Added enumeration of on-board types of serial ports (like SOC and OCP)
at using of the Sysfs backend on Linux.
* [QTBUG-40113] Fixed crash related to dynamic udev loading.
- QSerialPort:
* Fixed filtering of custom baud rate on Linux.
* [QTBUG-41295] Now the reading are not stalled on Windows when used the
read buffer with the limited size.
* Now the reading are not stalled on Windows after calling of the clear()
method.
* Now the bytesToWrite() on Windows returns the zero after WriteFile()
was called.
——————————————————我还是分割线——————————————————
重要更新:Qt串口模块5.5开始不再支持Qt4,所以建议用最后一个版本,qtserialport-opensource-src-5.4.2
下载地址:
http://pan.baidu.com/s/1o6UVlk2百度网盘
http://download.qt.io/official_releases/qt/5.4/5.4.2/submodules/官方
- QT:Qt4添加QSerialPort模块
- Qt4添加QSerialPort模块
- Qt4添加QSerialPort模块
- Qt4添加QSerialPort模块
- Qt:QSerialPort的多线程扩展
- QSerialPort
- QSerialPort
- Qt 串口类QSerialPort 使用笔记
- Qt 串口类QSerialPort 使用笔记
- Qt之串口类QSerialPort使用笔记
- Qt 串口类QSerialPort 使用笔记
- Qt 串口类QSerialPort 学习笔记
- (1)Qt利用QSerialPort使用串口
- Qt——QtSerialPort/QSerialPort(一)
- 使用QT-QSerialport打不开串口的原因
- Qt 串口类QSerialPort 使用笔记
- Qt 串口类QSerialPort 使用笔记
- Qt 使用QAxtiveX 模块编译异常问题 Qt4.8.0
- swift基础知识记录(一)
- Qt判断进程是否运行
- 策略模式的应用
- ZOJ-1005-Jugs【BFS+记录路径】
- 蓝桥杯_算法提高_学霸的迷宫(简单回溯法,没有减枝)
- QT:Qt4添加QSerialPort模块
- objective-c第三天 可变字符串和数组
- IOS学习之——画板 涂鸦
- Gson,Fast-Json解析 Demo
- poj 1979 Red and Black
- crash日志学习(初步)
- Matlab研究分析Gabor滤波器
- R for map(笔记1)
- 创建maven的web工程出现pom文件报错