为什么要使用QT,因为它是跨平台的。

我现在使用的环境是Win7 64bit,使用VS的编译器来编译QT工程。

安装这套环境简单说一下:先到QT官网下载qt-windows-opensource-5.1.1-msvc2012_opengl-x86_64-offline,然后安装它

(BUT,最近我把QtCreator改成使用Mingw编译了,直接下载带有Mingw32的版本就可以了,这样可以编译出同时在64和32下运行的程序!!)

再自己安装一个VS,我这里安装的是VS2012的

这样就可以在QT Creator中找到编译器了

我现在是打算使用QT来做一个串口收发工具,网上找了找相关的资料,发现有两种:qextserialport和QtSerialPort,前者在sourceforge里可以下载得到,后者嘛是QT自带的。我这里选择使用后者,可以参考下面网页上的资料:

http://qt-project.org/doc/qt-5.1/qtserialport/examples.html(已经失效)

http://qt-project.org/doc/qt-5/qtserialport-examples.html

由于我对QT也不太熟悉,所以我先弄一个最简单的控制台程序来开始串口编程。这里的例子就是cenumerator

新建一个QT控制台程序,很简单,选择了控制台程序之后都下一步就可以了。

把里面的源码下载下来,覆盖掉main.cpp

 /****************************************************************************
**
** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtSerialPort module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/ #include <QTextStream>
#include <QCoreApplication>
#include <QtSerialPort/QSerialPortInfo> QT_USE_NAMESPACE int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream out(stdout);
QList<QSerialPortInfo> serialPortInfoList = QSerialPortInfo::availablePorts(); out << QObject::tr("Total number of ports available: ") << serialPortInfoList.count() << endl; foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) {
out << endl
<< QObject::tr("Port: ") << serialPortInfo.portName() << endl
<< QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl
<< QObject::tr("Description: ") << serialPortInfo.description() << endl
<< QObject::tr("Manufacturer: ") << serialPortInfo.manufacturer() << endl
<< QObject::tr("Vendor Identifier: ") << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier(), ) : QByteArray()) << endl
<< QObject::tr("Product Identifier: ") << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier(), ) : QByteArray()) << endl
<< QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl;
} return ;
}

再把cenumerator.pro文件下载下来覆盖新建工程的pro文件,如果嫌烦那只要在我们的QT += core后面加上serialport即可(与core空格隔开)。

 #-------------------------------------------------
#
# Project created by QtCreator 2013-12-12T09:17:54
#
#------------------------------------------------- QT += core serialport QT -= gui TARGET = cenumerator
CONFIG += console
CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp

编译运行即可了。编译目录会在工程的上一级菜单中!这样的结构容易会把工程弄乱。

这会我把构建和运行中的默认构建目录改成当前文件,在删除了所有makefile文件之后,QT Creator可以正确地编译出exe文件来,但会提示“警告:Qmake不支持源文件目录下的构建目录”什么的云云。

虽然我们现在编译是没有问题,但这终究是一个隐患。

所以,最后我还是决定不去修改默认构建目录了,让它恢复成../build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name},这样默认情况下它还是在上级目录中生成中间文件及最终应用程序。但我对工程本身进行一些设置,使得QT会把编译得的中间文件保存到工程目录下面:

打开项目 -> 构建和运行 -> 概要,不再选中Shadow build,这样工程的编译就会在工程目录下面进行了,也不会再提示“警告:Qmake不支持源文件目录下的构建目录”的错误了。

喏,看现在所有文件都平躺着了,更清晰一些。

来运行一看看情况吧,枚举串口:

使用QT来制作串口终端的更多相关文章

  1. 使用串口终端安装AIX操作系统

    使用串口终端安装AIX操作系统 一.配置超级终端 首先,配置超级终端:在笔记本电脑上(Windows XP系统),点击开始à程序->附件->通讯->超级终端,配置名称为test的超级 ...

  2. QT 制作串口调试小助手----(小白篇)

    一.成品图展示 简介:因zigbee实验,制作一个相对简易版的上位机,接收来自zigbee无线传感采集的温湿度.光照等数据. 并且将数据部分描绘成实时动态折线统计图. 二.主要功能介绍 主要使用QT自 ...

  3. QT程序制作deb包并安装在应用程序菜单

    制作原理:打包:将QT制作的源程序(没有编译的)用debian压缩打包(这里是用脚本对源程序再编译)安装:将deb包中的源程序解压(默认解压到根目录)到规定系统文件中并编译(postinst脚本)卸载 ...

  4. OpenWrt固件刷入后串口终端没有反应的问题

    [路由器开发板硬件固件配置] MTK双频:MT7620a + MT7612e 内存:256 MB 闪存:16 MB 固件:MTK自带SDK中的OpenWrt固件(mtksdk-openwrt-2.6. ...

  5. Qt 自动搜索串口号列表

    @功能: SerialPortList 类实现当前可用的串口进行实时扫描,当发现有新的串口 或是现有串口消失时,SerialPortList类将发出一个QStringList类型的 信号onNewSe ...

  6. linux下串口调试工具/串口终端推荐: picocom

    对于picocom, kermit, minicom, picocom 最简单易用,也全然符合我的使用需求. 安装(mint / ubuntu): $ sudo apt-get install pic ...

  7. Qt中的串口编程之三

    QtSerialPort 今天我们来介绍一下QtSerialPort模块的源代码,学习一下该可移植的串口编程库是怎么实现的. 首先,我们下载好了源代码之后,使用QtCreator打开整个工程,可以看到 ...

  8. 【嵌入式linux】(第三步):安装串口终端 (ubuntu安装minicom串口终端)

    1.前言 我使用的是USB转串口,芯片是PL2303,貌似ubuntu自带了PL2303的USB驱动,可以直接使用,其它的USB转串口的没试过. 2.minicom安装 在终端中输入 : sudo a ...

  9. ARM-LINUX学习笔记-(虚拟机linux串口终端以及USB程序下载,基于TQ2440)

    昨天安装了ssh服务之后今天在windows上用xshell登陆发现登录不上,原因是使用了virtualbox的NAT模式,在NAT模式下,客户机可以很方便地上网,但是想要链接宿主机就需要打开网络地址 ...

随机推荐

  1. IOS总结_IOS经常使用的方法集合、调用系统电话、设备区分、APP内永不锁屏

    调用系统打电话的功能 打电话功能仅仅有iPhone支持,对于其它设备相应button应该禁用. //直接调用系统电话呼叫功能,挂断电话后不能回到应用程序 [UIApplication sharedAp ...

  2. 关于int全区变量读写的原子性

    关于int全区变量读写的原子性     关于int变量的读写是否原子性网上有非常多讨论,貌似不同平台不同,这里自己做实如今arm9平台測试.这里要注意原子性并不是指一条汇编才原子,实际上即使一次赋值编 ...

  3. BP简单的理解神经网络

    先用3类样本训练,在測试.. 刚開始学习的人有错的 地方,,请大家多多指导.. 一些好的博客: http://blog.csdn.net/starxu85/article/details/314353 ...

  4. UVa 699 落叶

    意甲冠军:我几乎不记得的题意!.! 它是一个长坑..我们从根节点开始,留下每一步,保存横坐标1,正确的一步加上横坐标1. 那么同样的横坐标统计data值总和. 思维:我来想,这可以递归成就.上就能够算 ...

  5. java反思reflect 分析Object物

    直接看它的一个例子 </pre><pre name="code" class="java">package reflect; impor ...

  6. (大数据工程师学习路径)第一步 Linux 基础入门----基本概念及操作

    本节联练习主要有: 1.环境介绍 2.常用 Shell 命令及快捷键 3.Linux 使用小技巧 一.Linux 桌面环境介绍 相对于现在的 Windows 系统,UNIX/Linux 本身是没有图形 ...

  7. 自己动手写CPU 笔记

    自己动手写CPU 跳转至: 导航. 搜索 文件夹 1 处理器与MIPS 2 可编程逻辑器件与Verilog HDL 3 教学版OpenMIPS处理器蓝图 4 第一条指令ori 5 逻辑.移位与nop ...

  8. Andriod Studio科普文章——3.大约gradle常见问题插头

    1.andriod gradle插件版本号过低. 错误位置: dependencies{ classpath 'com.android.tools.build:gradle:0.10.2' } 提示信 ...

  9. 使用ExpandableListView时间轴效果达到

    不废话,首先在地图上,查看结果 这是用ExpandableListView来实现时间轴效果,原理比較简单,以月份为第一级,以天为第二级来实现的. package com.hj.main; import ...

  10. Poj Roadblocks(次短路)

    Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best ...