当前位置:网站首页>QT serial port UI design and solution to display Chinese garbled code
QT serial port UI design and solution to display Chinese garbled code
2022-07-03 16:25:00 【Red guest white hat】
QT A serial port ui Design and solve the display of Chinese garbled code
【1】UTF-8 and GBK
*UTF-8:Unicode TransformationFormat-8bit, Allow to contain BOM, But it usually doesn't contain BOM.
Is used to solve the international character of a multi byte encoding , It uses English 8 position ( A byte ), Use of Chinese 24 by ( Three bytes ) Encoding .
UTF-8 Contains characters needed in all countries of the world , It's international code , Strong commonality .
UTF-8 Coded text can be supported in various countries UTF8 The character set is displayed on the browser .
If it is UTF8 code , In foreigners' English IE It can also show Chinese on , They don't have to download IE Chinese language support package for .
*GBK It's a national standard GB2312 On this basis, it is compatible after expansion GB2312 Standards for .
GBK The text encoding of is expressed in double bytes , That is to say, regardless of 、 English characters are represented by double bytes , In order to distinguish Chinese , Set the highest bit to 1.
GBK Contains all Chinese characters , It's the country code , Versatility is better than UTF8 Bad , however UTF8 The database occupied is more than GBD Big .
GBK yes GB2312 An extension of , In addition to compatibility GB2312 Outside , It can also display traditional Chinese , There are also Kanas in Japanese .
*GBK、GB2312 And so on UTF8 Between must pass through Unicode Code can be converted to each other : GBK、GB2312--Unicode--UTF8
UTF8--Unicode--GBK、GB2312
* In simplified Chinese windows Under the system ,ANSI Code representative GBK/GB2312 code ,ANSI Usually use 0x80~0xFF Scope 2 In bytes 1 Chinese characters .
0x00~0x7F Characters between , Is still 1 One byte stands for 1 Characters .Unicode(UTF-16) Encoding is used for all characters 2 Byte representation .
【2】SerialTool.pro

【3】mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QSerialPort>// Serial header file
#include<QTextCodec>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void InitUI();
private:
Ui::MainWindow *ui;
QTextCodec *codec;
};
#endif // MAINWINDOW_H
【4】mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("Serial Tool");
//codec = QTextCodec::codecForName("UTF-8");
codec = QTextCodec::codecForName("GBK");//System( Simplified Chinese windows By default, the system refers to GBK code )
QTextCodec::setCodecForLocale(codec);
InitUI();// Initialize serial port
}
MainWindow::~MainWindow()
{
delete ui;
}
// Initialize control
void MainWindow::InitUI()
{
// Port name
for(int i=0;i<10;i++)
{
ui->CB_portname->addItem(QString("COM%1").arg(i));// To add text 【 Additional form 】
}
// Baud rate 【 Additional form 】
ui->CB_btl->addItem(QString("1200") ,QSerialPort::Baud1200);
ui->CB_btl->addItem(QString("2400") ,QSerialPort::Baud2400);
ui->CB_btl->addItem(QString("4800") ,QSerialPort::Baud4800);
ui->CB_btl->addItem(QString("9600") ,QSerialPort::Baud9600);
ui->CB_btl->addItem(QString("19200") ,QSerialPort::Baud19200);
ui->CB_btl->addItem(QString("115200") ,QSerialPort::Baud115200);
// Data bits
ui->CB_databit->addItem(QString("5"),QSerialPort::Data5);
ui->CB_databit->addItem(QString("6"),QSerialPort::Data6);
ui->CB_databit->addItem(QString("7"),QSerialPort::Data7);
ui->CB_databit->addItem(QString("8"),QSerialPort::Data8);
// Parity bit
ui->CB_jioubit->addItem(codec->toUnicode(" nothing "),QSerialPort::NoParity);
ui->CB_jioubit->addItem(codec->toUnicode(" p. "),QSerialPort::EvenParity);
ui->CB_jioubit->addItem(codec->toUnicode(" accidentally "),QSerialPort::OddParity);
// Stop bit
ui->CB_stopbit->addItem(QString("1"),QSerialPort::OneStop);
ui->CB_stopbit->addItem(QString("1.5"),QSerialPort::OneAndHalfStop);
ui->CB_stopbit->addItem(QString("2"),QSerialPort::TwoStop);
// flow control
ui->CB_flowctrl->addItem("None",QSerialPort::NoFlowControl);// nothing
ui->CB_flowctrl->addItem("RTS/CTS",QSerialPort::HardwareControl);// Hardware control
ui->CB_flowctrl->addItem("XON/XOFF",QSerialPort::SoftwareControl);// Software control
}
【5】mainwindow.ui

【6】 Running effect

Love YOU
边栏推荐
- The difference between calling by value and simulating calling by reference
- From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
- QT串口ui设计和解决显示中文乱码
- Low level version of drawing interface (explain each step in detail)
- 【LeetCode】94. Middle order traversal of binary tree
- 疫情常态化大背景下,关于远程办公的思考|社区征文
- Is it safe to open a stock account by mobile registration? Does it need money to open an account
- Pointcut expression
- EditText request focus - EditText request focus
- How can technology managers quickly improve leadership?
猜你喜欢
![App mobile terminal test [4] APK operation](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [4] APK operation
![SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]](/img/3b/7523eca5bbcdbba29d9b7f6e4791a5.jpg)
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]

Myopia: take off or match glasses? These problems must be understood clearly first

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)

【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示

From the 18th line to the first line, the new story of the network security industry

Mysql 将逗号隔开的属性字段数据由列转行

Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!

The difference between calling by value and simulating calling by reference

QT串口ui设计和解决显示中文乱码
随机推荐
Unity项目优化案例一
The mixlab editing team is recruiting teammates~~
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Is it safe to open an account with tongdaxin?
June to - -------
高等数学(第七版)同济大学 习题2-1 个人解答
Register in PHP_ Globals parameter settings
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
nifi从入门到实战(保姆级教程)——flow
请求头不同国家和语言的表示
Pychart error updating package list: connect timed out
用同花顺炒股开户安全吗?
How to thicken the brush in the graphical interface
Record a jar package conflict resolution process
[combinatorics] combinatorial identity (sum of variable upper terms 1 combinatorial identity | summary of three combinatorial identity proof methods | proof of sum of variable upper terms 1 combinator
From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
Everyone in remote office works together to realize cooperative editing of materials and development of documents | community essay solicitation
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
远程办公之大家一同实现合作编辑资料和开发文档 | 社区征文