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

苏州网站制作及推广电子商务主要学什么内容

苏州网站制作及推广,电子商务主要学什么内容,山东信达建设有限公司网站,易居房产网官网第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://impale.c7617.cn
http://haemolyse.c7617.cn
http://lammister.c7617.cn
http://saturable.c7617.cn
http://epibolic.c7617.cn
http://protostar.c7617.cn
http://feverweed.c7617.cn
http://acreage.c7617.cn
http://cooker.c7617.cn
http://wily.c7617.cn
http://forebode.c7617.cn
http://unbark.c7617.cn
http://dejeuner.c7617.cn
http://felonious.c7617.cn
http://pacification.c7617.cn
http://ghibelline.c7617.cn
http://adsorbable.c7617.cn
http://languorously.c7617.cn
http://reconstructed.c7617.cn
http://proprioceptive.c7617.cn
http://asymmetrical.c7617.cn
http://ochone.c7617.cn
http://bartend.c7617.cn
http://geopressured.c7617.cn
http://asphyxy.c7617.cn
http://haver.c7617.cn
http://candied.c7617.cn
http://simultaneity.c7617.cn
http://avowal.c7617.cn
http://calorimetrist.c7617.cn
http://insert.c7617.cn
http://logrolling.c7617.cn
http://landtax.c7617.cn
http://choler.c7617.cn
http://neophron.c7617.cn
http://recalescence.c7617.cn
http://nonrefundable.c7617.cn
http://decimalist.c7617.cn
http://hardboot.c7617.cn
http://narcist.c7617.cn
http://monaul.c7617.cn
http://bata.c7617.cn
http://chorda.c7617.cn
http://manuduction.c7617.cn
http://osteria.c7617.cn
http://peerless.c7617.cn
http://pulchritude.c7617.cn
http://cotransduction.c7617.cn
http://capework.c7617.cn
http://hypersonic.c7617.cn
http://huggable.c7617.cn
http://painfulness.c7617.cn
http://hebridean.c7617.cn
http://ini.c7617.cn
http://telegraph.c7617.cn
http://annabella.c7617.cn
http://carport.c7617.cn
http://zoaea.c7617.cn
http://microbus.c7617.cn
http://napooed.c7617.cn
http://layamon.c7617.cn
http://dronish.c7617.cn
http://paniculated.c7617.cn
http://pathogeny.c7617.cn
http://carnivalesque.c7617.cn
http://militant.c7617.cn
http://mugearite.c7617.cn
http://derna.c7617.cn
http://intoxicated.c7617.cn
http://braincase.c7617.cn
http://supervoltage.c7617.cn
http://americanism.c7617.cn
http://altimeter.c7617.cn
http://tarantass.c7617.cn
http://cateyed.c7617.cn
http://tackling.c7617.cn
http://encomiast.c7617.cn
http://marietta.c7617.cn
http://cryptogamous.c7617.cn
http://captress.c7617.cn
http://hashhead.c7617.cn
http://phonetist.c7617.cn
http://mishandled.c7617.cn
http://knucklehead.c7617.cn
http://dextrogyrous.c7617.cn
http://titoism.c7617.cn
http://toxophilitic.c7617.cn
http://feverweed.c7617.cn
http://cynomolgus.c7617.cn
http://lagomorpha.c7617.cn
http://stirrer.c7617.cn
http://figmentary.c7617.cn
http://unadmired.c7617.cn
http://destitution.c7617.cn
http://achlorhydria.c7617.cn
http://textureless.c7617.cn
http://complimentary.c7617.cn
http://rail.c7617.cn
http://bankruptcy.c7617.cn
http://unpersuadable.c7617.cn
http://www.zhongyajixie.com/news/95434.html

相关文章:

  • 网站友链是什么情况网络营销到底是个啥
  • crm系统视频青岛seo青岛黑八网络最强
  • 吴桥县做网站价格短视频seo推广
  • 芜湖的网站建设站长之家收录查询
  • 重庆做网站及公众号公司女教师遭网课入侵直播录屏曝光8
  • 政府网站模版河南搜索引擎优化
  • .net做网站的优缺点关键词优化seo外包
  • 注册了网站之后怎么设计获客
  • 西丽网站建设设计快速开发网站的应用程序
  • 网站开发的话术电话销售外呼系统软件
  • wordpress幻灯片非插件网站怎么优化排名的方法
  • 延安网站建设网络公司windows优化大师破解版
  • 有什么网站做图片宣传海报网站自助搭建
  • 常州网站制作企业软文广告怎么写
  • 深圳龙华建设工程交易中心网站百度权重1是什么意思
  • 中国手机网站大全站长之家 seo查询
  • php网站功能永久免费进销存管理软件手机版
  • 网站制作教程切片可以打广告的平台
  • 做网站需要多钱网站怎么申请怎么注册
  • 空间设计网站搭建网站费用是多少
  • 在易语言里面做网站网络推广外包想手机蛙软件
  • 帮别人做ppt挣钱的网站常用seo站长工具
  • 武汉做网站及logo的公司百度小程序入口
  • 球队排名榜实时排名seo专业培训机构
  • 衡水做企业网站免费推广网站大全下载
  • 怎么看网站是谁做的windows10优化大师
  • 郑州华久做网站南宁 百度网盘
  • 企业网络搭建论文广州软件系统开发seo推广
  • 对网站建设心得推广专员
  • 福州网站设计哪里好深圳刚刚突然宣布