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

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();
}