qt版本:5.9.1

win版本:10.1706

本助手改自qt自带exmple中的terminal,去掉console相关内容,加入button textbowser textedit,只改变了mainwindow

下面是代码

/****************************************************************************
**
** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSerialPort module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtCore/QtGlobal>#include <QMainWindow>#include <QtSerialPort/QSerialPort>QT_BEGIN_NAMESPACEclass QLabel;namespace Ui {
class MainWindow;
}QT_END_NAMESPACEclass Console;
class SettingsDialog;class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void openSerialPort();void closeSerialPort();void about();void writeData(const QByteArray &data);void readData();void handleError(QSerialPort::SerialPortError error);void on_pushButton_clicked();void clearTextBrowser();
private:void initActionsConnections();private:void showStatusMessage(const QString &message);Ui::MainWindow *ui;QLabel *status;Console *console;SettingsDialog *settings;QSerialPort *serial;
};#endif // MAINWINDOW_H
/****************************************************************************
**
** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSerialPort module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include "console.h"
#include "settingsdialog.h"#include <QMessageBox>
#include <QLabel>
#include <QtSerialPort/QSerialPort>//! [0]
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{
//! [0]ui->setupUi(this);
//    console = new Console;
//    console->setEnabled(false);
//    setCentralWidget(console);
//! [1]serial = new QSerialPort(this);
//! [1]settings = new SettingsDialog;ui->actionConnect->setEnabled(true);ui->actionDisconnect->setEnabled(false);ui->actionQuit->setEnabled(true);ui->actionConfigure->setEnabled(true);status = new QLabel;ui->statusBar->addWidget(status);initActionsConnections();connect(serial, static_cast<void (QSerialPort::*)(QSerialPort::SerialPortError)>(&QSerialPort::error),this, &MainWindow::handleError);//! [2]connect(serial, &QSerialPort::readyRead, this, &MainWindow::readData);
//! [2]
//    connect(console, &Console::getData, this, &MainWindow::writeData);
//! [3]
}
//! [3]MainWindow::~MainWindow()
{delete settings;delete ui;
}//! [4]
void MainWindow::openSerialPort()
{SettingsDialog::Settings p = settings->settings();serial->setPortName(p.name);serial->setBaudRate(p.baudRate);serial->setDataBits(p.dataBits);serial->setParity(p.parity);serial->setStopBits(p.stopBits);serial->setFlowControl(p.flowControl);if (serial->open(QIODevice::ReadWrite)) {
//        console->setEnabled(true);
//        console->setLocalEchoEnabled(p.localEchoEnabled);ui->actionConnect->setEnabled(false);ui->actionDisconnect->setEnabled(true);ui->actionConfigure->setEnabled(false);showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6").arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits).arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));} else {QMessageBox::critical(this, tr("Error"), serial->errorString());showStatusMessage(tr("Open error"));}
}
//! [4]//! [5]
void MainWindow::closeSerialPort()
{if (serial->isOpen())serial->close();
//    console->setEnabled(false);ui->actionConnect->setEnabled(true);ui->actionDisconnect->setEnabled(false);ui->actionConfigure->setEnabled(true);showStatusMessage(tr("Disconnected"));
}
//! [5]void MainWindow::about()
{QMessageBox::about(this, tr("About Simple Terminal"),tr("The <b>Simple Terminal</b> example demonstrates how to ""use the Qt Serial Port module in modern GUI applications ""using Qt, with a menu bar, toolbars, and a status bar."));
}//! [6]
void MainWindow::writeData(const QByteArray &data)
{serial->write(data);
}
//! [6]//! [7]
void MainWindow::readData()
{
//    QByteArray data = serial->readAll();//    console->putData(data);QByteArray temp = serial->readAll();QString buf;if(!temp.isEmpty()){buf = temp;ui->textBrowser->setText(ui->textBrowser->document()->toPlainText() + buf);ui->textBrowser->moveCursor(QTextCursor::End);}}
//! [7]//! [8]
void MainWindow::handleError(QSerialPort::SerialPortError error)
{if (error == QSerialPort::ResourceError) {QMessageBox::critical(this, tr("Critical Error"), serial->errorString());closeSerialPort();}
}
//! [8]void MainWindow::initActionsConnections()
{connect(ui->actionConnect, &QAction::triggered, this, &MainWindow::openSerialPort);connect(ui->actionDisconnect, &QAction::triggered, this, &MainWindow::closeSerialPort);connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::close);connect(ui->actionConfigure, &QAction::triggered, settings, &SettingsDialog::show);connect(ui->actionClear, &QAction::triggered, this, &MainWindow::clearTextBrowser);connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::about);connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
}void MainWindow::showStatusMessage(const QString &message)
{status->setText(message);
}void MainWindow::on_pushButton_clicked()
{serial->write(ui->textEdit->toPlainText().toLatin1());
}void MainWindow::clearTextBrowser()
{ui->textBrowser->setText(NULL);
}

qt开发环境 - 丑陋的串口助手相关推荐

  1. Ubuntu下嵌入式Qt开发环境配置全攻略

    本文以友善之臂的Mini6410嵌入式开发板为目标板,介绍ubuntu 12.04系统下,配置嵌入式Qt开发工具的过程.本文中介绍的工具.大部分步骤和脚本来自开发板附带资料光盘,但其默认配置环境为老旧 ...

  2. qt开发环境的建立与qte4.6.3、tslib1.4的移植

    QT开发环境的建立以及qte4.6.3.tislib1.4移植到博创star2410开发板 1.首先是建立Linux开发环境 1.1.在windowsXP下安装博创公司提供的虚拟机软件VMware W ...

  3. qt工程在linux系统里颜色显示错误_【飞凌嵌入式RK3399开发板试用体验】+QT开发环境搭建测试(二)...

    作者:飞扬的青春 在拿到开发板之后,已经体验了Android操作系统,接下来就是体验Linux下的开发,本次以QT的一个小案例来测试下. 首先是自己先搭建了一个Ubuntu18.04的虚拟机,使用真机 ...

  4. Ubuntu 安装 Qt 开发环境 简单实现

    2019独角兽企业重金招聘Python工程师标准>>> Ubuntu 安装 Qt 开发环境 简单实现是本文要介绍的内容,内容很短,取其精华,详细介绍Qt 类库的说明,先来看内容. 一 ...

  5. 【Tools】Visual Studio 2019搭建Qt开发环境

    00. 目录 文章目录 00. 目录 01. 概述 02. Visual Studio 2019安装 03. Qt6安装 04. qt-vsaddin插件下载 05. qt-vsaddin插件安装 0 ...

  6. Ubuntu 安装 Qt 开发环境(转)

    Ubuntu 安装 Qt 开发环境 简单实现是本文要介绍的内容,内容很短,取其精华,详细介绍Qt 类库的说明,先来看内容. (转http://mobile.51cto.com/symbian-2718 ...

  7. linux系统中如何安装qwt,linux下Qt开发环境中qwt库的安装与使用

    qwt的安装与使用 安装好qt开发环境后,先去下载qwt库源代码. 以我下载的qwt-6.0.1.zip为例,解压得到qwt-6.0.1. 1.安装qwt-6.0.1 执行下面的命令:1 cd qwt ...

  8. QT GUI开发(一):保姆级VS2015配置QT开发环境

    QT GUI开发(一):保姆级VS2015配置QT开发环境 前言 一. QT环境搭建 1.1 QT安装 1.2 VS中安装工具库 二. QT简单工程示例 三. 小结 前言 做软件开发,特别是用户图形界 ...

  9. 嵌入式Qt开发环境搭建

    嵌入式Qt开发环境搭建 系统基础环境 系统更新 sudo apt update sudo apt upgrade sudo apt autoremove 安装常用软件 # 安装vim sudo apt ...

最新文章

  1. 2016年全球100G和200G相干WDM光学系统出货量增长75%
  2. 使用Nomad构建弹性基础架构: 作业生命周期
  3. docker mysql编辑器_docker官方mysql镜像自定义配置详解
  4. 反射获取空参数成员方法并运行
  5. Swin Transformer V2!MSRA原班人马提出了30亿参数版本的Swin Transformer!
  6. idea报“Usage of API documented as @since 1.7”这一问题的解决方法
  7. 使用echarts(一) 第一次使用echarts
  8. 信号学习第一课--基础知识
  9. 万能地图下载器下载谷歌卫星地图在ArcGIS中套合
  10. 如何导出html中的图片,一键保存网页中的全部图片
  11. 读书笔记——WebKit技术内幕 HTML结构
  12. 李欣桐 计算机竞赛,思维角逐 以赛促学 ——记义乌枫叶小学部第四届计算“小能手”比赛...
  13. 下载keep运动软件_Keep下载_Keep苹果官方免费版APP下载[健身运动]-下载之家
  14. git进阶 | 01 - git基础操作进阶
  15. 机器学习常用专业术语(英汉)
  16. 牛客网项目——前置技术(八):Kafka
  17. ThinkSNS+在研发过程中,如何做到 Laravel 配置可以网站后台...
  18. hook(2)Activity启动流程,安卓开发实战
  19. 数据窗口控件的函数Describe()
  20. 爬虫之requests-html爬取国外网站大全

热门文章

  1. oracle c#帮助文档下载,C#使用OracleClient连接Oracle数据库小记
  2. python读取图片上的文字_Python帮你读取图片中的文字(OCR)
  3. mysql storage_mySQL__storage课堂笔记和练习
  4. mysql重启root不能登_Mysql 5.7.28初始化使用root无法登录
  5. java面向对象小程序_java运用面向对象的思想实现计算器的小程序
  6. [蓝桥杯][2018年第九届真题]全球变暖(DFS)
  7. MySQL innosetup_使用Inno Setup 打包jdk、mysql、tomcat、webapp等为一个exe安装包
  8. python序列类型tuple_Python常用的序列类型包括列表、元组和字典三种。
  9. 老九java线上,老九 - SegmentFault 思否
  10. 算法分析设计--递归算法