QtQStringEx

update QtQStringEx and READ.md
This commit is contained in:
touwoyimuli@gmail.com 2019-08-18 20:12:45 +08:00
parent 20faa16653
commit 922ba02c7c
9 changed files with 461 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -35,6 +35,9 @@ HEADERS += \
FORMS += \
ExWidget.ui
RC_ICONS += QT_win_32x32.ico
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin

84
QtQStringEx/ExQString.cpp Normal file
View File

@ -0,0 +1,84 @@
#include "ExQString.h"
#include "ui_ExQString.h"
#include <QString>
ExQString::ExQString(QWidget *parent) :
QWidget(parent),
ui(new Ui::ExQString)
{
ui->setupUi(this);
setWindowTitle(QObject::tr("2/8/10/16进制互相转化"));
}
ExQString::~ExQString()
{
delete ui;
}
void ExQString::on_btnResult_clicked()
{
float a = ui->editA->text().toFloat();
float b = ui->editB->text().toFloat();
float m_val = a * b;
QString str = QString::number(static_cast<double>(m_val), 'f', 2);
ui->editC->setText(str);
}
void ExQString::on_btn2_clicked()
{
QString str = ui->edit2->text();
bool ok;
int val = str.toInt(&ok, 2); //获取二进制
str = str.setNum(val, 8); //显示八进制
ui->edit8->setText(str);
str = str.setNum(val, 10); //显示十进制
ui->edit10->setText(str);
str = str.setNum(val, 16); //显示十六进制
ui->edit16->setText(str);
}
void ExQString::on_btn8_clicked()
{
QString str = ui->edit8->text();
bool ok;
int val = str.toInt(&ok, 8);
str = str.setNum(val, 2);
ui->edit2->setText(str);
str = str.setNum(val, 10);
ui->edit10->setText(str);
str = str.setNum(val, 16);
ui->edit16->setText(str);
}
void ExQString::on_btn10_clicked()
{
QString str = ui->edit10->text();
bool ok;
int val = str.toInt(&ok, 10);
str = str.setNum(val, 2);
ui->edit2->setText(str);
str = str.setNum(val, 8);
ui->edit8->setText(str);
str = str.setNum(val, 16);
ui->edit16->setText(str);
}
void ExQString::on_btn16_clicked()
{
QString str = ui->edit16->text();
bool ok;
int val = str.toInt(&ok, 16);
str = str.setNum(val, 2);
ui->edit2->setText(str);
str = str.setNum(val, 8);
ui->edit8->setText(str);
str = str.setNum(val, 10);
ui->edit10->setText(str);
}

31
QtQStringEx/ExQString.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef EXQSTRING_H
#define EXQSTRING_H
#include <QWidget>
namespace Ui {
class ExQString;
}
class ExQString : public QWidget
{
Q_OBJECT
public:
explicit ExQString(QWidget *parent = nullptr);
~ExQString();
private slots:
void on_btnResult_clicked();
void on_btn2_clicked();
void on_btn8_clicked();
void on_btn10_clicked();
void on_btn16_clicked();
private:
Ui::ExQString *ui;
float m_val;
};
#endif // EXQSTRING_H

189
QtQStringEx/ExQString.ui Normal file
View File

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExQString</class>
<widget class="QWidget" name="ExQString">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>194</height>
</rect>
</property>
<property name="windowTitle">
<string>ExQString</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lab">
<property name="text">
<string>QString获取LineEdit文本进制之间转换</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="editA">
<property name="text">
<string>10</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labMul">
<property name="text">
<string>*</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editB">
<property name="text">
<string>6.72</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labEqual">
<property name="text">
<string>=</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editC"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnResult">
<property name="text">
<string>计算</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="lab16">
<property name="text">
<string>十六进制</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="edit16"/>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="edit10"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lab2">
<property name="text">
<string>二进制</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lab10">
<property name="text">
<string>十进制</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lab8">
<property name="text">
<string>八进制</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="edit2"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="edit8"/>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="btn2">
<property name="text">
<string>转换</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="btn8">
<property name="text">
<string>转换</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="btn10">
<property name="text">
<string>转换</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="btn16">
<property name="text">
<string>转换</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,44 @@
#-------------------------------------------------
#
# Project created by QtCreator 2019-08-18T12:06:43
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtQStringEx
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
ExQString.cpp
HEADERS += \
ExQString.h
FORMS += \
ExQString.ui
RC_ICONS += QT_win_32x32.ico
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES +=

11
QtQStringEx/main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "ExQString.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ExQString w;
w.show();
return a.exec();
}

100
README.md
View File

@ -1,2 +1,100 @@
# QtExamples
Qt5 各个控件使用的一个例子、以及一些底层原理或者技巧性的理解
<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/img/20190818185031.png"/>
我也不知道为什么,就是想放这么一张图在这里。
## 项目介绍:
Qt5 各个控件使用的一个例子、以及一些底层原理或者技巧性的理解,即是自己所学记录,亦可以互相交流共享学习,**有朋自远方互联网而来,不亦说乎?**
刚大学毕业,大二开始正式(日以继夜的敲)学习c/c++路线知识但今年已经的毕业虽然学习过程中距今学习qt知识也有一年多了中间有写一些比如[**中国象棋**](https://blog.csdn.net/qq_33154343/article/details/89284983)**QQ**(的 [登录](https://blog.csdn.net/qq_33154343/article/details/80448144)/ [私聊](https://blog.csdn.net/qq_33154343/article/details/79341062)、[群聊](https://blog.csdn.net/qq_33154343/article/details/96437681)等功能),**但是却总是感觉有一种半路出家的学习qt的柑橘**,想着`c++`的知识还算学习的比较系统且完备(个人感觉)。一直在想要不要过的轻松点把qt给**推到重来**期间犹豫不定工作的话用到相关知识再去百度谷歌一下够用即可后面或许会去学习其他部分的知识qt也许只是一个过渡呢但是写着写着发现这个跨平台是真的好用越发发现其设计的简洁、方便还带一种设计的美感让我逐渐沉迷其中近日想清楚了**下定决心,还是推倒重来**全过程的熟悉和了解的qt的所有相关或许期间会比较辛苦(毕竟还附带同时维护两个blog和一个github)但是我想着以qt为媒介学会使用、思想、架构设计、经验或许会耗时一两年吧倘若那个时候这个系列也已经写完了的话应该对这个也有一定的认知到时候再去接触学习更高的平台和架构思想应该会有较大的帮助。算是一个人生今后的一个短暂规划学习不用急于求成而焦虑自然水到渠成。
2019-08-18
## 说明:
会将该系列的源码文章等系列全部托管于这个仓库该系列的主线任务只是讲解qt的相关文章超出或者其他部分。
<font color=#70AD47 size=4 face="幼圆">**开发环境:**</font> `win10 x64 专业版 1803` <font color=#70AD47 size=4 face="幼圆">**操作系统版本**</font>`17134.829`
<font color=#70AD47 size=4 face="幼圆">**开发软件:** </font> `Qt Creator 4.8.2 (Enterprise)``Qt 5.9.8`
<font color=#70AD47 size=4 face="幼圆">**编码语言:**</font>![](https://img.shields.io/badge/language-c++-orange.svg)
<font color=#70AD47 size=4 face="幼圆">**支持平台:**</font>![](https://img.shields.io/conda/pn/conda-forge/qt?style=plastic)
<br>
## 项目文章系列:
### 第一部分:预备知识
- `windows`环境下安装`Qt Creator`作为`c++`的**IDE**开发工具,学习和使用**qt** (推荐)
- [Qt Creator 安装SDK在MSVC编译模式下使用CDB调试器](https://blog.csdn.net/qq_33154343/article/details/98779698)
- `windows`环境下安装`Qt Creator` + `Visual Studio 2015`作为`c++`的`IDE`开发工具,学习和使用**qt** (备选)
- [`windows`环境下安装`Qt Creator 5.9` + `Visual Studio 2017专业版`](https://blog.csdn.net/qq_33154343/article/details/78587699) 参考此文 (备选)
- `Qt Creator` **IDE**的界面组成和使用讲解
- 编写一个**qt**的第一个项目: `Hello World`的项目
### 第二部分qt生成原理/运行机制
- [`make` `makefile` `cmake` `qmake`都是什么,有什么区别?](https://blog.csdn.net/qq_33154343/article/details/98170236)
### 第三部分:常用控件
### 补充部分:补充较杂的知识点
##### 乱码相关:
- [ 输出乱码原因:古文码、口字码、符号码、问号码、棍拷码](https://blog.csdn.net/qq_33154343/article/details/99617767)
- [qt5 中文乱码解决](https://blog.csdn.net/qq_33154343/article/details/95344312)
- [Qt字符串有中文编译不通过解决方法](https://blog.csdn.net/qq_33154343/article/details/79130275)
- [乱码原因Qt版本_附上语文的pdf版本](https://blog.csdn.net/qq_33154343/article/details/79039644)
- [qt中文乱码问题](https://blog.csdn.net/qq_33154343/article/details/78686103)
- [借Qt中文乱码谈谈Coding中的编码问题](https://blog.csdn.net/qq_33154343/article/details/78686075)
- [Qt5与Qt4的信号接收差异](https://blog.csdn.net/qq_33154343/article/details/79130732)
- `qt`的信号和槽关系
- `qt`中Lam表达式
###
<br>
## 编译
倘若自己的个人版本,不同于作者,且又编译运行屡次失败,**靠谱方法**:请重装系统之后,安装与我的同一版本,发开编程环境[qt-opensource-windows-x86-5.9.8.exe](http://download.qt.io/archive/qt/5.9/5.9.8/qt-opensource-windows-x86-5.9.8.exe)。 请使用下载**这一版本**5.9.8的`QtCreator`编译运行项目,可以保证运行成功 使用Desktop Qt 5.9.8 MinGW 32 bit 直接编译运行)
<br>
## 互助
若是帮助到了你,可以点击该项目的的<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709023321.png" height="18" width="18"/> **Star**<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709023317.png" height="18" width="18"/> **Fork** 的两个图标,方便抬手之间,表示点个赞,手有余香
<br>
## 关于作者:
<font color=#70AD47 size=4 face="幼圆">**touwoyimuli** </font> touwoyimuli@gmai.com [作者更多联系方式](https://touwoyimuli.github.io/about/)
<br>
## 协议:
<img src='https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709052645.png' width='127' height='51'/>
<font color=#70AD47 size=4 face="幼圆">**touwoyimuli**</font> 博客代码基于GNU General Public License v3.0 协议进行分发和使用,更多信息参见[协议文件](/LICENSE)。
<img src='https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709052632.png' width='145.77' height='51'/>
<font color=#70AD47 size=4 face="幼圆">**touwoyimuli**</font> 所含文章使用以下协议进行保护:[署名-非商业性使用-禁止演绎](http://creativecommons.org/licenses/by-nc-nd/3.0/cn/)。