当前位置:网站首页>QT (VI) value and string conversion
QT (VI) value and string conversion
2022-07-27 15:58:00 【51CTO】
List of articles
One 、UI Design
New projects , The main options are shown below : One QWidget, belt ui file , And preliminary Ui Design
Drag components :QLable,QPushButton,QlineEdit.

details ui file
<?xml
version="1.0" encoding="UTF-8"?>
<
ui
version=
"4.0"
>
<
class
>Widget
</
class
>
<
widget
class=
"QWidget"
name=
"Widget"
>
<
property
name=
"geometry"
>
<
rect
>
<
x
>0
</
x
>
<
y
>0
</
y
>
<
width
>511
</
width
>
<
height
>203
</
height
>
</
rect
>
</
property
>
<
property
name=
"windowTitle"
>
<
string
>Widget
</
string
>
</
property
>
<
layout
class=
"QGridLayout"
name=
"gridLayout_3"
>
<
item
row=
"0"
column=
"0"
>
<
layout
class=
"QGridLayout"
name=
"gridLayout"
>
<
item
row=
"0"
column=
"0"
>
<
widget
class=
"QLabel"
name=
"label"
>
<
property
name=
"text"
>
<
string
> Number :
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"0"
column=
"1"
>
<
widget
class=
"QLineEdit"
name=
"lineEditNum"
>
<
property
name=
"text"
>
<
string
>12
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"0"
column=
"2"
rowspan=
"2"
>
<
spacer
name=
"horizontalSpacer"
>
<
property
name=
"orientation"
>
<
enum
>Qt::Horizontal
</
enum
>
</
property
>
<
property
name=
"sizeHint"
stdset=
"0"
>
<
size
>
<
width
>17
</
width
>
<
height
>20
</
height
>
</
size
>
</
property
>
</
spacer
>
</
item
>
<
item
row=
"0"
column=
"3"
>
<
widget
class=
"QLabel"
name=
"label_2"
>
<
property
name=
"text"
>
<
string
> The unit price :
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"0"
column=
"4"
>
<
widget
class=
"QLineEdit"
name=
"lineEditPrice"
>
<
property
name=
"text"
>
<
string
>5.0
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"1"
column=
"1"
>
<
widget
class=
"QPushButton"
name=
"pushButton"
>
<
property
name=
"text"
>
<
string
> Calculation
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"1"
column=
"3"
>
<
widget
class=
"QLabel"
name=
"label_3"
>
<
property
name=
"text"
>
<
string
> The total price :
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"1"
column=
"4"
>
<
widget
class=
"QLineEdit"
name=
"lineEditTotal"
/>
</
item
>
</
layout
>
</
item
>
<
item
row=
"1"
column=
"0"
>
<
spacer
name=
"verticalSpacer"
>
<
property
name=
"orientation"
>
<
enum
>Qt::Vertical
</
enum
>
</
property
>
<
property
name=
"sizeHint"
stdset=
"0"
>
<
size
>
<
width
>20
</
width
>
<
height
>9
</
height
>
</
size
>
</
property
>
</
spacer
>
</
item
>
<
item
row=
"2"
column=
"0"
>
<
layout
class=
"QGridLayout"
name=
"gridLayout_2"
>
<
item
row=
"0"
column=
"1"
>
<
widget
class=
"QLineEdit"
name=
"lineEditTen"
>
<
property
name=
"text"
>
<
string
>15
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"2"
column=
"2"
>
<
widget
class=
"QPushButton"
name=
"pushButton_4"
>
<
property
name=
"text"
>
<
string
> Convert to other bases
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"0"
column=
"2"
>
<
widget
class=
"QPushButton"
name=
"pushButton_2"
>
<
property
name=
"text"
>
<
string
> Convert to other bases
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"1"
column=
"0"
>
<
widget
class=
"QLabel"
name=
"label_5"
>
<
property
name=
"text"
>
<
string
> Binary system :
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"2"
column=
"1"
>
<
widget
class=
"QLineEdit"
name=
"lineEditHex"
/>
</
item
>
<
item
row=
"2"
column=
"0"
>
<
widget
class=
"QLabel"
name=
"label_6"
>
<
property
name=
"text"
>
<
string
> Hexadecimal :
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"1"
column=
"2"
>
<
widget
class=
"QPushButton"
name=
"pushButton_3"
>
<
property
name=
"text"
>
<
string
> Convert to other bases
</
string
>
</
property
>
</
widget
>
</
item
>
<
item
row=
"1"
column=
"1"
>
<
widget
class=
"QLineEdit"
name=
"lineEditSec"
/>
</
item
>
<
item
row=
"0"
column=
"0"
>
<
widget
class=
"QLabel"
name=
"label_4"
>
<
property
name=
"text"
>
<
string
> Decimal system :
</
string
>
</
property
>
</
widget
>
</
item
>
</
layout
>
</
item
>
</
layout
>
</
widget
>
<
resources
/>
<
connections
/>
</
ui
>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
Two 、 Code development
Code using “ Go to slot “ The generated code
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace
Ui {
class
Widget; }
QT_END_NAMESPACE
class
Widget :
public
QWidget
{
Q_OBJECT
public:
Widget(
QWidget
*
parent
=
nullptr);
~Widget();
private
slots:
void
on_pushButton_clicked();
void
on_pushButton_2_clicked();
void
on_pushButton_3_clicked();
private:
Ui::Widget
*
ui;
};
#endif
// WIDGET_H
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(
QWidget
*
parent)
:
QWidget(
parent)
,
ui(
new
Ui::Widget)
{
ui
->
setupUi(
this);
}
Widget::~Widget()
{
delete
ui;
}
void
Widget::on_pushButton_clicked()
{
QString
str
=
ui
->
lineEditNum
->
text();
int
num
=
str.
toInt();
str
=
ui
->
lineEditPrice
->
text();
float
price
=
str.
toFloat();
float
total
=
num
*
price;
str
=
str.
setNum(
total,
'f',
2);
ui
->
lineEditTotal
->
setText(
str);
}
void
Widget::on_pushButton_2_clicked()
{
QString
str
=
ui
->
lineEditTen
->
text();
int
value
=
str.
toInt();
str
=
str.
setNum(
value,
2);
ui
->
lineEditSec
->
setText(
str);
str
=
str.
setNum(
value,
16);
ui
->
lineEditHex
->
setText(
str.
toUpper());
}
void
Widget::on_pushButton_3_clicked()
{
QString
str
=
ui
->
lineEditSec
->
text();
bool
ok;
int
value
=
str.
toInt(
&
ok,
2);
// Read in... In binary
ui
->
lineEditTen
->
setText(
QString::number(
value));
ui
->
lineEditHex
->
setText(
QString::number(
value,
16).
toUpper());
}
void
Widget::on_pushButton_4_clicked()
{
QString
str
=
ui
->
lineEditHex
->
text();
bool
ok;
int
value
=
str.
toInt(
&
ok,
16);
// Read... In hexadecimal
ui
->
lineEditTen
->
setText(
QString::number(
value));
ui
->
lineEditSec
->
setText(
QString::number(
value,
2));
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
3、 ... and 、 Demonstration effect
There is no fault tolerance here , When entering characters, especially : Binary can only be :01, Hexadecimal can only be :0-9A-F.

边栏推荐
- [Yunxiang book club issue 13] common methods of viewing media information and processing audio and video files in ffmpeg
- 无线网络分析有关的安全软件(aircrack-ng)
- [regular expression] matching grouping
- busybox login: can't execute '/bin/bash': No such file or directory 解决方法
- 【云享读书会第13期】音频文件的封装格式和编码格式
- DRF学习笔记(三):模型类序列化器ModelSerializer
- 初识结构体
- Spark RPC
- go语言慢速入门——go运算符
- 突发!海康/大华/商汤/旷视/依图/科大讯飞等28家中国实体被美列入黑名单
猜你喜欢

Spark 3.0 adaptive execution code implementation and data skew optimization

Implement custom spark optimization rules

C语言:自定义类型

网络原理(1)——基础原理概述

Network principle (2) -- network development

CAS比较交换的知识、ABA问题、锁升级的流程

Three uses of static keyword

Division of entity classes (VO, do, dto)

语音直播系统——提升云存储安全性的必要手段

网络原理(2)——网络开发
随机推荐
Catalog component design and custom extended catalog implementation in spark3
DRF学习笔记(三):模型类序列化器ModelSerializer
C语言:扫雷小游戏
Troubleshooting the slow startup of spark local programs
Spark Bucket Table Join
The difference between synchronized and reentrantlock
DRF学习笔记(准备)
突发!海康/大华/商汤/旷视/依图/科大讯飞等28家中国实体被美列入黑名单
Inter thread wait and wake-up mechanism, singleton mode, blocking queue, timer
【云享读书会第13期】视频文件的编码格式
网络原理(1)——基础原理概述
[regular expression] single character matching
初识MySQL数据库
无线网络分析有关的安全软件(aircrack-ng)
Static关键字的三种用法
[正则表达式] 匹配开头和结尾
C language: Sanzi game
The shell script reads the redis command in the text and inserts redis in batches
折半插入排序
线程中死锁的成因及解决方案