Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
三雷科技
QT博客案例
提交
a68633dd
Q
QT博客案例
项目概览
三雷科技
/
QT博客案例
通知
1542
Star
47
Fork
34
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
QT博客案例
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a68633dd
编写于
11月 26, 2023
作者:
L
leiyuanxiang@uniontech.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SophomoreWin
update
上级
ef1c04da
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
394 addition
and
0 deletion
+394
-0
c++/school/SophomoreWin/.gitignore
c++/school/SophomoreWin/.gitignore
+73
-0
c++/school/SophomoreWin/SophomoreWin.pro
c++/school/SophomoreWin/SophomoreWin.pro
+25
-0
c++/school/SophomoreWin/main.cpp
c++/school/SophomoreWin/main.cpp
+26
-0
c++/school/SophomoreWin/mainwindow.cpp
c++/school/SophomoreWin/mainwindow.cpp
+16
-0
c++/school/SophomoreWin/mainwindow.h
c++/school/SophomoreWin/mainwindow.h
+16
-0
c++/school/SophomoreWin/math_impl.cpp
c++/school/SophomoreWin/math_impl.cpp
+75
-0
c++/school/SophomoreWin/math_impl.h
c++/school/SophomoreWin/math_impl.h
+28
-0
c++/school/SophomoreWin/sophomore_widget.cpp
c++/school/SophomoreWin/sophomore_widget.cpp
+87
-0
c++/school/SophomoreWin/sophomore_widget.h
c++/school/SophomoreWin/sophomore_widget.h
+48
-0
未找到文件。
c++/school/SophomoreWin/.gitignore
0 → 100644
浏览文件 @
a68633dd
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
c++/school/SophomoreWin/SophomoreWin.pro
0 → 100644
浏览文件 @
a68633dd
QT
+=
core
gui
greaterThan
(
QT_MAJOR_VERSION
,
4
)
:
QT
+=
widgets
CONFIG
+=
c
++
11
#
You
can
make
your
code
fail
to
compile
if
it
uses
deprecated
APIs
.
#
In
order
to
do
so
,
uncomment
the
following
line
.
#
DEFINES
+=
QT_DISABLE_DEPRECATED_BEFORE
=
0
x060000
#
disables
all
the
APIs
deprecated
before
Qt
6.0
.
0
SOURCES
+=
\
main
.
cpp
\
mainwindow
.
cpp
\
math_impl
.
cpp
\
sophomore_widget
.
cpp
HEADERS
+=
\
mainwindow
.
h
\
math_impl
.
h
\
sophomore_widget
.
h
#
Default
rules
for
deployment
.
qnx
:
target
.
path
=
/
tmp
/
$$
{
TARGET
}
/
bin
else
:
unix
:
!
android
:
target
.
path
=
/
opt
/
$$
{
TARGET
}
/
bin
!
isEmpty
(
target
.
path
)
:
INSTALLS
+=
target
c++/school/SophomoreWin/main.cpp
0 → 100644
浏览文件 @
a68633dd
#
include
"mainwindow.h"
#include <QApplication>
#include <QTextCodec>
int
main
(
int
argc
,
char
*
argv
[])
{
QApplication
a
(
argc
,
argv
);
//设置中文编码
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
QTextCodec
*
codec
=
QTextCodec
::
codecForName
(
"GBK"
);
#else
QTextCodec
*
codec
=
QTextCodec
::
codecForName
(
"UTF-8"
);
#endif
QTextCodec
::
setCodecForLocale
(
codec
);
QTextCodec
::
setCodecForCStrings
(
codec
);
QTextCodec
::
setCodecForTr
(
codec
);
#else
QTextCodec
*
codec
=
QTextCodec
::
codecForName
(
"UTF-8"
);
QTextCodec
::
setCodecForLocale
(
codec
);
#endif
MainWindow
w
;
w
.
show
();
return
a
.
exec
();
}
c++/school/SophomoreWin/mainwindow.cpp
0 → 100644
浏览文件 @
a68633dd
#
include
"mainwindow.h"
#include <QDebug>
#include <QString>
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
)
{
sp_widget
=
new
SophomoreWidget
(
this
);
setCentralWidget
(
sp_widget
);
}
MainWindow
::~
MainWindow
()
{
}
c++/school/SophomoreWin/mainwindow.h
0 → 100644
浏览文件 @
a68633dd
#
ifndef
MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "sophomore_widget.h"
class
MainWindow
:
public
QMainWindow
{
Q_OBJECT
public:
MainWindow
(
QWidget
*
parent
=
nullptr
);
~
MainWindow
();
private:
SophomoreWidget
*
sp_widget
;
};
#endif // MAINWINDOW_H
c++/school/SophomoreWin/math_impl.cpp
0 → 100644
浏览文件 @
a68633dd
#
include
"math_impl.h"
#include <QString>
MathImpl
::
MathImpl
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
int
MathImpl
::
generateRandomNumber
(
int
min
,
int
max
)
{
if
(
min
==
max
&&
min
==
0
){
return
0
;
}
return
(
rand
()
%
(
max
-
min
))
+
min
+
1
;
}
int
MathImpl
::
doCount
(
int
num1
,
int
num2
,
QString
op
)
{
if
(
op
==
"+"
){
return
num1
+
num2
;
}
else
if
(
"-"
==
op
){
return
num1
-
num2
;
}
else
if
(
"*"
==
op
){
return
num1
*
num2
;
}
return
0
;
}
// 先乘后加减 a*b+c
const
QString
MathImpl
::
fun1
()
{
int
num1
=
generateRandomNumber
(
2
,
7
);
int
num2
=
generateRandomNumber
(
2
,
7
);
int
num3
=
generateRandomNumber
(
10
,
50
);
QString
tmp
=
QString
::
number
(
num1
)
+
" * "
+
QString
::
number
(
num2
)
+
" + "
+
QString
::
number
(
num3
)
+
" = "
;
return
tmp
;
}
// 先乘后加减 a*b-c
const
QString
MathImpl
::
fun2
()
{
QString
tmp
;
int
num1
,
num2
,
num3
;
do
{
num1
=
generateRandomNumber
(
2
,
7
);
num2
=
generateRandomNumber
(
2
,
7
);
num3
=
generateRandomNumber
(
10
,
100
);
}
while
(
num1
*
num2
<
num3
);
tmp
=
QString
::
number
(
num1
)
+
" * "
+
QString
::
number
(
num2
)
+
" - "
+
QString
::
number
(
num3
)
+
" = "
;
return
tmp
;
}
// 先乘后加减 a/b+c
const
QString
MathImpl
::
fun3
()
{
QString
tmp
;
int
num1
,
num2
,
num3
;
num1
=
generateRandomNumber
(
2
,
6
);
num2
=
generateRandomNumber
(
2
,
6
);
num3
=
generateRandomNumber
(
10
,
50
);
tmp
=
QString
::
number
(
num1
*
num2
)
+
" ÷ "
+
QString
::
number
(
num2
)
+
" + "
+
QString
::
number
(
num3
)
+
" = "
;
return
tmp
;
}
// 先除后减 a÷b-c
const
QString
MathImpl
::
fun4
()
{
QString
tmp
;
int
num1
,
num2
,
num3
;
do
{
num1
=
generateRandomNumber
(
2
,
6
);
num2
=
generateRandomNumber
(
2
,
6
);
num3
=
generateRandomNumber
(
2
,
6
);
}
while
(
num1
<
num3
);
tmp
=
QString
::
number
(
num1
*
num2
)
+
" ÷ "
+
QString
::
number
(
num2
)
+
" - "
+
QString
::
number
(
num3
)
+
" = "
;
return
tmp
;
}
c++/school/SophomoreWin/math_impl.h
0 → 100644
浏览文件 @
a68633dd
#
ifndef
MATH_H
#define MATH_H
#include <QObject>
class
MathImpl
:
public
QObject
{
Q_OBJECT
public:
explicit
MathImpl
(
QObject
*
parent
=
nullptr
);
int
generateRandomNumber
(
int
min
,
int
max
);
// 先乘后加 a*b+c
const
QString
fun1
();
// 先乘后减 a*b-c
const
QString
fun2
();
// 先除后加 a*b+c
const
QString
fun3
();
// 先除后减 a*b-c
const
QString
fun4
();
private:
int
doCount
(
int
num1
,
int
num2
,
QString
op
);
signals:
};
#endif // MATH_H
c++/school/SophomoreWin/sophomore_widget.cpp
0 → 100644
浏览文件 @
a68633dd
#
pragma
execution_character_set
(
"utf-8"
)
#include "sophomore_widget.h"
#include <QCheckBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QtDebug>
#include <QLabel>
#include <QSpinBox>
#include <QLineEdit>
#include <QFile>
#include <QTextStream>
SophomoreWidget
::
SophomoreWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
,
m
(
new
MathImpl
(
this
))
,
m_checkboxFun1
(
new
QCheckBox
())
,
m_checkboxFun2
(
new
QCheckBox
())
,
m_checkboxFun3
(
new
QCheckBox
())
,
m_checkboxFun4
(
new
QCheckBox
())
,
m_layoutNum
(
new
QHBoxLayout
)
,
m_layoutMain
(
new
QVBoxLayout
)
,
m_btn
(
new
QPushButton
(
"生成题目"
,
this
))
,
m_labNum
(
new
QLabel
(
"题目数量:"
))
,
m_SpinBoxNum
(
new
QSpinBox
)
{
initUI
();
initConnect
();
}
void
SophomoreWidget
::
slotClickBtn
()
{
functionPointers
.
clear
();
if
(
m_checkboxFun1
->
isChecked
()){
functionPointers
.
push_back
(
&
MathImpl
::
fun1
);
}
if
(
m_checkboxFun2
->
isChecked
()){
functionPointers
.
push_back
(
&
MathImpl
::
fun2
);
}
if
(
m_checkboxFun3
->
isChecked
()){
functionPointers
.
push_back
(
&
MathImpl
::
fun3
);
}
if
(
m_checkboxFun4
->
isChecked
()){
functionPointers
.
push_back
(
&
MathImpl
::
fun4
);
}
for
(
int
i
=
0
;
i
<
700
;
i
++
)
{
int
r
=
m
->
generateRandomNumber
(
0
,
static_cast
<
int
>
(
functionPointers
.
size
()
-
1
)
);
QString
result
=
(
m
->*
(
functionPointers
[
r
]))();
qWarning
()
<<
result
;
}
}
void
SophomoreWidget
::
initUI
()
{
m_checkboxFun1
->
setText
(
tr
(
"题型:a*b+c"
));
m_checkboxFun1
->
setChecked
(
true
);
m_checkboxFun2
->
setText
(
"题型:a*b-c"
);
m_checkboxFun2
->
setChecked
(
true
);
m_checkboxFun3
->
setText
(
"题型:a*b+c"
);
m_checkboxFun3
->
setChecked
(
true
);
m_checkboxFun4
->
setText
(
"题型:a*b-c"
);
m_checkboxFun4
->
setChecked
(
true
);
m_SpinBoxNum
->
setMaximum
(
1000
);
m_SpinBoxNum
->
setValue
(
100
);
m_layoutNum
->
addWidget
(
m_labNum
);
m_layoutNum
->
addWidget
(
m_SpinBoxNum
);
m_layoutMain
->
addLayout
(
m_layoutNum
);
m_layoutMain
->
addWidget
(
m_btn
);
m_layoutMain
->
addWidget
(
m_checkboxFun1
);
m_layoutMain
->
addWidget
(
m_checkboxFun2
);
m_layoutMain
->
addWidget
(
m_checkboxFun3
);
m_layoutMain
->
addWidget
(
m_checkboxFun4
);
setLayout
(
m_layoutMain
);
}
void
SophomoreWidget
::
initConnect
()
{
connect
(
m_btn
,
&
QPushButton
::
clicked
,
this
,
&
SophomoreWidget
::
slotClickBtn
);
}
void
SophomoreWidget
::
saveFile
(
QString
fileName
)
{
}
c++/school/SophomoreWin/sophomore_widget.h
0 → 100644
浏览文件 @
a68633dd
#
ifndef
SOPHOMORE_WIDGET_H
#define SOPHOMORE_WIDGET_H
#include <QWidget>
#include "math_impl.h"
class
QCheckBox
;
class
QPushButton
;
class
QVBoxLayout
;
class
QHBoxLayout
;
class
QSpinBox
;
class
QLabel
;
class
QLineEdit
;
typedef
const
QString
(
MathImpl
::*
ClassFunction
)();
class
SophomoreWidget
:
public
QWidget
{
Q_OBJECT
public:
explicit
SophomoreWidget
(
QWidget
*
parent
=
nullptr
);
signals:
public
slots
:
void
slotClickBtn
();
private:
void
initUI
();
void
initConnect
();
void
saveFile
(
QString
fileName
);
MathImpl
*
m
;
std
::
vector
<
ClassFunction
>
functionPointers
;
QCheckBox
*
m_checkboxFun1
;
QCheckBox
*
m_checkboxFun2
;
QCheckBox
*
m_checkboxFun3
;
QCheckBox
*
m_checkboxFun4
;
QHBoxLayout
*
m_layoutNum
;
QVBoxLayout
*
m_layoutMain
;
QPushButton
*
m_btn
;
// 选择保存文件路径的按钮
QPushButton
*
m_btnSavevFile
;
// 显示文件路径
QLineEdit
*
m_edtSaveFileName
;
QLabel
*
m_labNum
;
QSpinBox
*
m_SpinBoxNum
;
};
#endif // SOPHOMORE_WIDGET_H
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录