资源简介

Qt5串口通信实例-windows

资源截图

代码片段和文件信息

#include “frmmain.h“
#include “ui_frmmain.h“
#include “myStaticClass.h“

frmMain::frmMain(QWidget *parent) :
        QWidget(parent)
        ui(new Ui::frmMain)
{
    ui->setupUi(this);

    FormHelper::FormInCenter(this);
    FormHelper::FormNotResize(this);    

    this->setWindowIcon(QIcon(“:/2.ico“));
    this->setWindowtitle(tr(“串口调试工具Windows版V1.2(QQ:517216493)“));

    this->InitForm();
    //安装监听器
    ui->txtSend->installEventFilter(this);
}

frmMain::~frmMain()
{
    delete ui;
}

//监听鼠标双击则清空接收数据
void frmMain::mouseDoubleClickEvent(QMouseEvent *e)
{
    if (e->button()==Qt::LeftButton)
    {
        ui->txtDataHex->clear();
    }
}

//监听回车键
bool frmMain::eventFilter(Qobject *obj QEvent *event)
{
    if (obj==ui->txtSend)
    {
        if (event->type()==QEvent::KeyPress)
        {
            QKeyEvent *keyEvent=static_cast(event);
            if (keyEvent->key()==Qt::Key_Return || keyEvent->key()==Qt::Key_Enter)
            {
                this->WriteMyCom();
                return true;
            }
        }
    }

    return Qobject::eventFilter(objevent);
}

void frmMain::InitForm()
{
    ReceiveCount=0;
    SendCount=0;
    this->IsShow=true;
    this->IsAutoClear=false;
    this->IsAutoSave=false;
    this->IsAutoSend=false;
    this->IsInit=false;

    QStringList comList;//串口号
    QStringList baudList;//波特率
    QStringList parityList;//校验位
    QStringList dataBitsList;//数据位
    QStringList stopBitsList;//停止位

    comList.clear();
    comList<<“COM1“<<“COM2“<<“COM3“<<“COM4“<<“COM5“<<“COM6“
            <<“COM7“<<“COM8“<<“COM9“<<“COM10“<<“COM11“<<“COM12“
            <<“COM13“<<“COM14“<<“COM15“<<“COM16“<<“COM17“<<“COM18“
            <<“COM19“<<“COM20“<<“COM21“<<“COM22“<<“COM23“<<“COM24“
            <<“COM25“<<“COM26“<<“COM27“<<“COM28“<<“COM28“<<“COM29“<<“COM30“;
    ui->cboxPortName->clear();
    ui->cboxPortName->addItems(comList);
    ui->cboxPortName->setCurrentIndex(0);

    baudList.clear();
    baudList<<“50“<<“75“<<“100“<<“134“<<“150“<<“200“<<“300“
            <<“600“<<“1200“<<“1800“<<“2400“<<“4800“<<“9600“
            <<“14400“<<“19200“<<“38400“<<“56000“<<“57600“
            <<“76800“<<“115200“<<“128000“<<“256000“;
    ui->cboxBaudRate->clear();
    ui->cboxBaudRate->addItems(baudList);
    ui->cboxBaudRate->setCurrentIndex(12);

    parityList.clear();
    parityList<<“无“<<“奇“<<“偶“<<“标志“<<“空格“;
    ui->cboxParity->clear();
    ui->cboxParity->addItems(parityList);
    ui->cboxParity->setCurrentIndex(0);

    dataBitsList.clear();
    dataBitsList<<“5“<<“6“<<“7“<<“8“;
    ui->cboxDataBit->clear();
    ui->cboxDataBit->addItems(dataBitsList);
    ui->cboxDataBit->setCurrentIndex(3);

    stopBitsList.clear();
    stopBitsList<<“1“<<“1.5“<<“2“;
    ui->cboxStopBit->clear();
    ui->cboxStopBit->addItems(stopBitsList);
    ui->cboxStopBit->setCurrentIndex(0);

    ui->cboxSend->clear();
    ui->cboxSave

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-10 22:08  Qt5串口通信实例-win\
     文件       99678  2012-09-05 14:48  Qt5串口通信实例-win\1.ico
     文件       99678  2012-09-05 14:48  Qt5串口通信实例-win\2.ico
     文件       13756  2021-01-08 15:06  Qt5串口通信实例-win\frmmain.cpp
     文件        2075  2013-03-14 13:17  Qt5串口通信实例-win\frmmain.h
     文件       13363  2013-03-14 13:18  Qt5串口通信实例-win\frmmain.ui
     文件         275  2021-01-08 14:49  Qt5串口通信实例-win\main.cpp
     文件          56  2012-09-05 14:48  Qt5串口通信实例-win\main.rc
     文件        5777  2013-03-13 10:01  Qt5串口通信实例-win\Makefile
     文件        8055  2013-03-13 10:01  Qt5串口通信实例-win\Makefile.Debug
     文件        8086  2013-03-13 10:01  Qt5串口通信实例-win\Makefile.Release
     文件         662  2013-03-13 09:17  Qt5串口通信实例-win\myinclude.h
     文件         111  2012-09-05 14:48  Qt5串口通信实例-win\myResource.qrc
     文件       16515  2021-01-08 15:03  Qt5串口通信实例-win\myStaticClass.h
     文件         686  2021-01-08 14:53  Qt5串口通信实例-win\myWindowsSerialportTools.pro
     文件       41874  2021-01-08 15:00  Qt5串口通信实例-win\myWindowsSerialportTools.pro.user
     文件        7990  2013-03-14 14:00  Qt5串口通信实例-win\myWindowsSerialportTools.pro.user.4
     文件        6531  2013-03-13 09:17  Qt5串口通信实例-win\qextserialbase.cpp
     文件        6876  2013-03-13 09:17  Qt5串口通信实例-win\qextserialbase.h
     文件        6877  2021-01-10 20:19  Qt5串口通信实例-win\qextserialbase.h.autosave
     文件         384  2012-09-05 14:48  Qt5串口通信实例-win\readme.txt
     文件       34891  2021-01-08 15:06  Qt5串口通信实例-win\win_qextserialport.cpp
     文件        4479  2013-03-13 09:17  Qt5串口通信实例-win\win_qextserialport.h

评论

共有 条评论