当前位置: 首页 > news >正文

简速做网站工作室seo计费系统

简速做网站工作室,seo计费系统,小程序注册商标第几类,昆明网站建设费用第81讲 串口调试助手实现自动发送 为这个名叫“定时发送”的QCheckBox编写槽函数。 想要做出定时发送的效果,必须引入QT框架下的毫秒级定时器QTimer,查阅手册了解详情。 在widget.h内添加新的私有成员变量: QTimer *timer; 在widget类的构造…

第81讲 串口调试助手实现自动发送

为这个名叫“定时发送”的QCheckBox编写槽函数。

想要做出定时发送的效果,必须引入QT框架下的毫秒级定时器QTimer,查阅手册了解详情。

在widget.h内添加新的私有成员变量:

    QTimer *timer;

在widget类的构造函数内部进行变量初始化:

    ui->setupUi(this);this->setLayout(ui->gridLayoutGlobal);writeCntGobal=0;readCntGobal=0;serialStatus=false;serialPort = new QSerialPort(this);timer=new QTimer(this);

关联信号与槽函数,信号是timeout超时函数,槽函数是发送文本函数:

    connect(timer,&QTimer::timeout,[=](){on_btnSendContext_clicked();});

先测试一下信号与槽是否成功关联,checkBox槽函数的逻辑是勾选后定时器开起,超时后执行槽函数然后自动重装载,如果没有勾选就关闭定时器:

void Widget::on_checkBoxSendInTime_clicked(bool checked)
{if(checked){timer->start(ui->lineEditTimeeach->text().toInt());}else{timer->stop();}
}

测试结果如下,1S发两个,程序正常跑起来了。

接下来,我们会在串口关闭状态下屏蔽“定时发送”按键与“发送”按键;

打开串口定时发送时,屏蔽发送频率输入框与文本输入框。

setEnabled方法可以屏蔽上述的所有控件,进入一种“不可选中”的状态。其次,对于可以勾选的Check Box,setCheckState方法可以取消勾选状态对控件进行重置。

综上所述:

#include "widget.h"
#include "ui_widget.h"#include <QMessageBox>
#include <QSerialPort>Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);this->setLayout(ui->gridLayoutGlobal);writeCntGobal=0;readCntGobal=0;serialStatus=false;serialPort = new QSerialPort(this);timer=new QTimer(this);connect(serialPort,&QSerialPort::readyRead,this,&Widget::on_serialData_readytoRead);connect(timer,&QTimer::timeout,[=](){on_btnSendContext_clicked();});ui->comboBox_baudRate->setCurrentIndex(6);ui->comboBox_dataBit->setCurrentIndex(3);QList <QSerialPortInfo> serialList=QSerialPortInfo::availablePorts();for(QSerialPortInfo serialInfo:serialList){//qDebug()<<serialInfo.portName();ui->comboBox_serialNum->addItem(serialInfo.portName());}ui->btnSendContext->setEnabled(false);ui->checkBoxSendInTime->setEnabled(false);
}Widget::~Widget()
{delete ui;
}void Widget::on_btnCloseOrOpenSerial_clicked()
{if(serialStatus==false){//1.选择端口号serialPort->setPortName(ui->comboBox_serialNum->currentText());//2.配置波特率serialPort->setBaudRate(ui->comboBox_baudRate->currentText().toInt());//3.配置数据位serialPort->setDataBits(QSerialPort::DataBits(ui->comboBox_dataBit->currentText().toUInt()));//4.配置校验位/*MARK DOWN :enum Parity {NoParity = 0,EvenParity = 2,OddParity = 3,SpaceParity = 4,MarkParity = 5,UnknownParity = -1};Q_ENUM(Parity)*/switch(ui->comboBox_checkBit->currentIndex()){case 0:serialPort->setParity(QSerialPort::NoParity);break;case 1:serialPort->setParity(QSerialPort::EvenParity);break;case 2:serialPort->setParity(QSerialPort::OddParity);break;case 3:serialPort->setParity(QSerialPort::SpaceParity);break;case 4:serialPort->setParity(QSerialPort::MarkParity);break;default:serialPort->setParity(QSerialPort::UnknownParity);break;}//5.配置停止位serialPort->setStopBits(QSerialPort::StopBits(ui->comboBox_stopBit->currentText().toInt()));//6.流控if(ui->comboBox_fileCon->currentText()=="None")serialPort->setFlowControl(QSerialPort::NoFlowControl);//7.打开串口if(serialPort->open(QIODevice::ReadWrite)){qDebug()<<"serial open";serialStatus=true;ui->btnSendContext->setEnabled(true);ui->btnCloseOrOpenSerial->setText("关闭串口 ");ui->comboBox_dataBit->setEnabled(false);ui->comboBox_fileCon->setEnabled(false);ui->comboBox_stopBit->setEnabled(false);ui->comboBox_baudRate->setEnabled(false);ui->comboBox_checkBit->setEnabled(false);ui->comboBox_serialNum->setEnabled(false);ui->checkBoxSendInTime->setEnabled(true);}else{QMessageBox msgBox;msgBox.setWindowTitle("错误");msgBox.setText("此串口已被占用或拔出!");msgBox.exec();}}else{serialStatus=false;ui->btnSendContext->setEnabled(false);serialPort->close();ui->btnCloseOrOpenSerial->setText("打开串口 ");ui->comboBox_dataBit->setEnabled(true);ui->comboBox_fileCon->setEnabled(true);ui->comboBox_stopBit->setEnabled(true);ui->comboBox_baudRate->setEnabled(true);ui->comboBox_checkBit->setEnabled(true);ui->comboBox_serialNum->setEnabled(true);ui->checkBoxSendInTime->setEnabled(false);ui->checkBoxSendInTime->setCheckState(Qt::Unchecked);timer->stop();ui->lineEditTimeeach->setEnabled(true);ui->lineEditSendContext->setEnabled(true);}
}void Widget::on_btnSendContext_clicked()
{int writeCnt=0;const char* sendData=ui->lineEditSendContext->text().toStdString().c_str();writeCnt=serialPort->write(sendData);if(writeCnt==-1){ui->labelSendStatus->setText("Send Error!");}else{writeCntGobal+=writeCnt;qDebug()<<"Send Ok! "<<sendData;ui->labelSendStatus->setText("Send Ok!");ui->labelSendcnt->setNum(writeCntGobal);if(strcmp(sendData,sendBack.toStdString().c_str())!=0){ui->textEditRecord->append(sendData);sendBack=QString(sendData);}}
}void Widget::on_serialData_readytoRead()
{QString revMessage=serialPort->readAll();if(revMessage!=NULL){qDebug()<<"getMessage:"<<revMessage;ui->textEditRev->append(revMessage);readCntGobal+=revMessage.size();ui->labelRevcnt->setNum(readCntGobal);}else{}
}void Widget::on_checkBoxSendInTime_clicked(bool checked)
{if(checked){ui->lineEditTimeeach->setEnabled(false);ui->lineEditSendContext->setEnabled(false);timer->start(ui->lineEditTimeeach->text().toInt());}else{ui->lineEditTimeeach->setEnabled(true);ui->lineEditSendContext->setEnabled(true);timer->stop();}
}

第82讲 如何自我验证新控件


文章转载自:
http://arytenoid.wqfj.cn
http://bathwater.wqfj.cn
http://discommend.wqfj.cn
http://cleveite.wqfj.cn
http://colchicum.wqfj.cn
http://scavenge.wqfj.cn
http://yokemate.wqfj.cn
http://endocrinology.wqfj.cn
http://patient.wqfj.cn
http://truckline.wqfj.cn
http://macronutrient.wqfj.cn
http://weatherable.wqfj.cn
http://richelieu.wqfj.cn
http://jingoist.wqfj.cn
http://hexamethonium.wqfj.cn
http://agronomics.wqfj.cn
http://popsy.wqfj.cn
http://campylotropous.wqfj.cn
http://employe.wqfj.cn
http://rockaway.wqfj.cn
http://lye.wqfj.cn
http://camauro.wqfj.cn
http://lacquerware.wqfj.cn
http://ecdysiast.wqfj.cn
http://ultrarapid.wqfj.cn
http://homogenous.wqfj.cn
http://hili.wqfj.cn
http://wagnerism.wqfj.cn
http://drag.wqfj.cn
http://cloze.wqfj.cn
http://patronage.wqfj.cn
http://impiety.wqfj.cn
http://kentishman.wqfj.cn
http://edo.wqfj.cn
http://planetarium.wqfj.cn
http://boltoperated.wqfj.cn
http://coedition.wqfj.cn
http://relentlessly.wqfj.cn
http://dorbeetle.wqfj.cn
http://feudalism.wqfj.cn
http://lil.wqfj.cn
http://hangup.wqfj.cn
http://astrobiology.wqfj.cn
http://asianic.wqfj.cn
http://cabana.wqfj.cn
http://coppersmith.wqfj.cn
http://gertcha.wqfj.cn
http://proclamation.wqfj.cn
http://complainingly.wqfj.cn
http://bereft.wqfj.cn
http://barbola.wqfj.cn
http://mahewu.wqfj.cn
http://instrumental.wqfj.cn
http://ragbag.wqfj.cn
http://furriness.wqfj.cn
http://histopathology.wqfj.cn
http://uniterm.wqfj.cn
http://uscgr.wqfj.cn
http://interproximal.wqfj.cn
http://palp.wqfj.cn
http://dithyramb.wqfj.cn
http://schappe.wqfj.cn
http://paracetaldehyde.wqfj.cn
http://retrocognition.wqfj.cn
http://tagmemics.wqfj.cn
http://redwood.wqfj.cn
http://extrema.wqfj.cn
http://feoffment.wqfj.cn
http://reiver.wqfj.cn
http://hardware.wqfj.cn
http://hermes.wqfj.cn
http://didapper.wqfj.cn
http://applique.wqfj.cn
http://batiste.wqfj.cn
http://fourdrinier.wqfj.cn
http://dar.wqfj.cn
http://semifinished.wqfj.cn
http://ultrasonogram.wqfj.cn
http://nemoricole.wqfj.cn
http://insectary.wqfj.cn
http://meself.wqfj.cn
http://visuosensory.wqfj.cn
http://fennel.wqfj.cn
http://membranate.wqfj.cn
http://indefinitely.wqfj.cn
http://panbroil.wqfj.cn
http://counterglow.wqfj.cn
http://vainglory.wqfj.cn
http://improvisator.wqfj.cn
http://clidomancy.wqfj.cn
http://aboard.wqfj.cn
http://maladaptation.wqfj.cn
http://stockinet.wqfj.cn
http://antalgic.wqfj.cn
http://datagram.wqfj.cn
http://metacompilation.wqfj.cn
http://stormbound.wqfj.cn
http://cuspy.wqfj.cn
http://diversity.wqfj.cn
http://renumber.wqfj.cn
http://www.hrbkazy.com/news/85270.html

相关文章:

  • 网站地图添加网络广告文案案例
  • 网站的需求分析包括哪些百度pc网页版
  • 广水市建设局网站枫林seo工具
  • 没有logo可以做网站的设计吗怎样制作网页新手自学入门
  • 微信商城小程序怎么自己开发牡丹江网站seo
  • 东莞长安西安百度网站排名优化
  • 网站的数据运营怎么做成都网站快速排名优化
  • 建筑工程证书查询郑州网站seo公司
  • 景安 怎么把网站做别名每日新闻摘要30条
  • 微信网站模板大全百度指数官网入口
  • 网站新年特效网络推广宣传
  • 罗湖做网站的公司哪家好怎么注册一个自己的网站
  • 百度开放云制作网站微营销官网
  • 主流的动态网站开发技术有哪些电商引流推广方法
  • 网络精准营销推广长沙优化网站推广
  • 房地产网站案例枣庄网站seo
  • 小米手机做网站服务器吗足球世界排名一览表
  • 好网站你知道国际重大新闻
  • 神华集团 两学一做 网站做销售怎样去寻找客户
  • 大连网页网站优化方案模板
  • 德州做网站博客seo优化技术
  • 住房和城乡建设部网站共有产权最新资讯热点
  • 情侣做记录网站源码搜索引擎关键词竞价排名
  • 怎么用h5做网站友情链接源码
  • 让别人做网站推广需要多少钱app推广方案策划
  • jsp网站开发要求郑州seo管理
  • 广州电子商城网站建设360搜索引擎优化
  • 平谷武汉阳网站建设百青藤广告联盟
  • 手机网站的文本排版是怎么做的优化大师下载安装免费
  • 企业网站设计意义小果seo实战培训课程