当前位置:网站首页>Qt development -- compilation of serial port assistant
Qt development -- compilation of serial port assistant
2022-06-09 08:59:00 【Lee1989 Qi】
One 、 Create a project
Create a normal widget Project engineering , Control for code research . Create a compilation test project . You can compile it for the next step .
Two 、 A serial port UI Interface design
1、 choice ui Control
- The serial port receives the data display interface control of the lower computer

- Select container 、 Baud rate 、 Serial number 、 Controls for multiple selection containers such as data bits

- Upper computer serial port to send data control

- Make some advertisements , Add your own elements , For example, the author's telephone number and other personal information

- Finally, after the layout, the effect is as follows :

2、 Set up UI Default display
- Containers 、 Baud rate 、 Serial number 、 Controls for multiple selection containers such as data bits

- Modify the property name of the control , Easy to write code for debugging

3、 Add serial port identification code
#include <qserialportinfo.h>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QStringList serialNamePort;
foreach(const QSerialPortInfo &info ,QSerialPortInfo::availablePorts()){
serialNamePort<<info.portName();
}
ui->Serial->addItems(serialNamePort);
}
The effect is as follows :
3、 ... and 、 Realize the logic function of the button :
When opening the serial port button, you need to initialize the serial port , That is, a series of parameters for initializing the serial port , The following is the initialization code .
QSerialPort::BaudRate baudrate;
QSerialPort::DataBits databits;
QSerialPort::StopBits stopbits;
QSerialPort::Parity parity;
if(ui->bote->currentText() == "1200"){
baudrate = QSerialPort::Baud1200;
}else if(ui->bote->currentText() == "4800"){
baudrate = QSerialPort::Baud4800;
}else if(ui->bote->currentText() == "9600"){
baudrate = QSerialPort::Baud9600;
}else if(ui->bote->currentText() == "38400"){
baudrate = QSerialPort::Baud38400;
}else if(ui->bote->currentText() == "115200"){
baudrate = QSerialPort::Baud115200;
}
if(ui->shujubit->currentText() == "5"){
databits = QSerialPort::Data5;
}else if(ui->shujubit->currentText() == "6"){
databits = QSerialPort::Data6;
}else if(ui->shujubit->currentText() == "7"){
databits = QSerialPort::Data7;
}else if(ui->shujubit->currentText() == "8"){
databits = QSerialPort::Data8;
}
if(ui->closebit->currentText() == "1"){
stopbits = QSerialPort::OneStop;
}else if(ui->closebit->currentText() == "1.5"){
stopbits = QSerialPort::OneAndHalfStop;
}else if(ui->closebit->currentText() == "2"){
stopbits = QSerialPort::TwoStop;
}
if(ui->jiaoyanwei->currentText() == "None"){
parity = QSerialPort::NoParity;
}else if(ui->jiaoyanwei->currentText() == "Odd"){
parity = QSerialPort::OddParity;
}else if(ui->jiaoyanwei->currentText() == "Even"){
parity = QSerialPort::EvenParity;
}
Then set corresponding parameters
serilaPort->setPortName(ui->Serial->currentText());
serilaPort->setBaudRate(baudrate);
serilaPort->setDataBits(databits);
serilaPort->setStopBits(stopbits);
serilaPort->setParity(parity);
Add button event , Pop up the prompt box .
if(serilaPort->open(QIODevice::ReadWrite) == true){
QMessageBox::information(this," Tips "," success ");
}else {
QMessageBox::critical(this," Tips "," Failure ");
}
Write slot function for serial port display
Learning output :
Tips : Here is the total number of learning plans
for example :
- Technical notes 2 All over
- CSDN Technology blogs 3 piece
- Habitual vlog video 1 individual
边栏推荐
- Oracle locally managed tablespaces
- How to solve the problem of mouseup event invalidation
- Acwing第 54 场周赛
- Sql: reformat department table (row to column problem: group by + aggregate function)
- 【程序人生】互联网岗位分工;互联网开发流程;职责分工
- 48-oidc OP configuration information endpoint
- Modify campaign table
- Use of extensions and super
- SQL: 重新格式化部门表 (行转列问题:Group by + 聚合函数)
- 【Redis学习13】Redis搭建主从集群、哨兵集群、分片集群
猜你喜欢

成本节省 50%,9人团队使用函数计算开发 wolai 在线文档应用

Residual current relay uses residual current transformer to detect residual current and prevent electrical fire

编辑器说明-备用

【Redis学习13】Redis搭建主从集群、哨兵集群、分片集群

10种提问型爆文标题句式 直接套用

Modifier le tableau des activités de marché

85. (leaflet house) leaflet military plotting - line arrow drawing

Modify campaign table

Shared network port settings for Dell Idrac express version

防火门监控系统对防火门状态进行24小时实时自动巡检
随机推荐
Nodejs使用Net模块创建TCP服务器和客户端
3D programming mode: dependent isolation mode
Huawei machine test, hj6 prime factor
2022年5月29日16:05:09
Use Flashback Database and restore point
vim的简单使用
Shared network port settings for Dell Idrac express version
Compilation_ Basic concepts
Update and delete operations in Clickhouse of data warehouse series
测试不会被开发取代吗?
[antenna] [1] explanation of some nouns and simple concepts
[untitled]
shellcode编写
安科瑞综合能效管理系统在数据中心的应用
Acwing第 54 场周赛
Configuring the environment for RMAN backups_ Configure backup optimization
面向高校 | “云原生技术应用与实践”示范课程项目开放申报
深度解析:二十五岁做软件测试前景怎么样?
Summary of string inversion methods
The fire door monitoring system carries out 24-hour real-time automatic inspection on the status of the fire door