3.QT计算机实战
- mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
void run();
~MainWindow(); private slots:
void on_pushButton_clicked(); void on_num1_textChanged(const QString &arg1); private:
Ui::MainWindow *ui;
}; #endif // MAINWINDOW_H - mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "op.h"
#include <QDebug> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} const QString op1("+");
const QString op2("-");
const QString op3("*");
const QString op4("/"); void MainWindow::on_pushButton_clicked()
{
qDebug()<<"hello"<<endl;
op ops;
bool isok;
QString str1 = ui->num1->text();
QString str2 = ui->op->text();
QString str3 = ui->num2->text();
//保存结果
QString str4;
int a = str1.toInt(&isok,);
int b = str3.toInt(&isok,); ops.seta(a);
ops.setb(b); if(str2 == op1)
{
str4.sprintf("%d",ops.add());
qDebug()<<str4<<endl;
}
else if(str2 == op2)
{
str4.sprintf("%d",ops.sub());
qDebug()<<str4<<endl;
}
else if(str2 == op3)
{
str4.sprintf("%d",ops.mul());
qDebug()<<str4<<endl;
}
else if(str2 == op4)
{
str4.sprintf("%d",ops.divv());
qDebug()<<str4<<endl;
}
ui->textEdit->setText(str4);
} void MainWindow::run()
{
qDebug()<<"hello"<<endl;
op ops;
bool isok;
QString str1 = ui->num1->text();
QString str2 = ui->op->text();
QString str3 = ui->num2->text();
//保存结果
QString str4;
int a = str1.toInt(&isok,);
int b = str3.toInt(&isok,); ops.seta(a);
ops.setb(b); if(str2 == op1)
{
str4.sprintf("%d",ops.add());
qDebug()<<str4<<endl;
}
else if(str2 == op2)
{
str4.sprintf("%d",ops.sub());
qDebug()<<str4<<endl;
}
else if(str2 == op3)
{
str4.sprintf("%d",ops.mul());
qDebug()<<str4<<endl;
}
else if(str2 == op4)
{
str4.sprintf("%d",ops.divv());
qDebug()<<str4<<endl;
}
ui->textEdit->setText(str4);
} void MainWindow::on_num1_textChanged(const QString &arg1)
{
qDebug()<<"hello"<<endl;
op ops;
//父类存储子类对象的地址
QObject *pobj = &ops; bool isok;
QString str1 = ui->num1->text();
int a = str1.toInt(&isok,);
if(!isok)
{
ui->num1->clear();
}
} - op.h
#ifndef OP_H
#define OP_H #include <QObject> class op : public QObject
{
Q_OBJECT
public:
explicit op(QObject *parent = nullptr);
int add();
int sub();
int mul();
int divv(); public:
void seta(int data);
void setb(int data);
int geta();
int getb(); private:
int a;
int b; signals: public slots:
}; #endif // OP_H - op.cpp
#include "op.h" op::op(QObject *parent) : QObject(parent)
{
a = b = ;
} int op::add()
{
return a+b;
} int op::sub()
{
return a-b;
} int op::mul()
{
return a*b;
} int op::divv()
{
return a/b;
} void op::seta(int data)
{
a = data;
} void op::setb(int data)
{
b = data;
} int op::geta()
{
return a;
} int op::getb()
{
return b;
} - main.cpp
#include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show(); return a.exec();
}
3.QT计算机实战的更多相关文章
- Visual Studio 2015开发Qt项目实战经验分享(附项目示例源码)
Visual Studio 2015开发Qt项目实战经验分享(附项目示例源码) 转 https://blog.csdn.net/lhl1124281072/article/details/800 ...
- QT开发实战精解
无法打开包括文件<QApplication> No such file or directory 这一问题 解决办法,使用QApplication时必须在项目pro文件中添加一句 QT ...
- PyQT5速成教程-4 Qt Designer实战[上]
本文由 沈庆阳 所有,转载请与作者取得联系! 前言 在前面几节的学习中,我们对PyQt的基本使用.Qt Designer与Python编码的工作流程有了基本的学习.同时也掌握了Qt Designer中 ...
- PyQt(Python+Qt)实战:使用QCamera、QtMultimedia等实现摄像头拍照
一.概述 在PyQt中,可以使用QCamera.QCameraViewfinder.QCameraViewfinderSettings等一系列多媒体操作相关类实现摄像头操作.用这些类不足50行代码+U ...
- Qt 新手实战项目之手把手打造一个串口助手
一前景 很多时候我们在学习一门新的语言,一直在学习各种语法和记住各种关键字,很容易产生枯燥的情绪,感觉学习这些玩意儿不知道用在什么地方,心里很是苦恼,这不,我在这记录下我学习Qt的第一个的小项目-串口 ...
- C++ Qt 项目实战(一)之文本编辑器
文本编辑器例图 项目开发环境 系统版本:windows10 QT 版本: 5.9.9 开发语言:C++ 已实现功能 文件操作:新建,打开,保存,另存为,打印,退出 编辑操作:复制,粘贴,剪切,查找,替 ...
- 第15.40节、PyQt(Python+Qt)实战:moviepy实现MP4视频转gif动图的工具
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.引言 在写<第15.39节.splitDockWidget和 ...
- 项目实战:Qt+OpenCV大家来找茬(Qt抓图,穿透应用,识别左右图区别,框选区别,微调位置)
前言 本项目的出现理由只是笔者的一个念头,于是利用专业Qt和Opencv相关的知识开发一个辅助工具,本文章仅用于Qt和Opencv结合的学习. Demo演示效果 运行包下载地 ...
- 【Qt编程】基于Qt的词典开发系列<一>--词典框架设计及成品展示
去年暑假的时候,作为学习Qt的实战,我写了一个名为<我爱查词典>的词典软件.后来由于导师项目及上课等原因,时间不足,所以该软件的部分功能欠缺,性能有待改善.这学期重新拿出来看时,又有很多东 ...
随机推荐
- tflearn中一些CNN RNN的例子
lstm.py # -*- coding: utf-8 -*- """ Simple example using LSTM recurrent neural networ ...
- 蓝桥杯--算法提高 排列数 (简单dfs)
算法提高 排列数 时间限制:1.0s 内存限制:256.0MB 问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入 ...
- 依赖注入Unity框架
依赖注入和控制反转是对同一件事情的不同描述,从某个方面讲,就是它们描述的角度不同.依赖注入是从应用程序的角度在描述,可以把依赖注入描述完整点:应用程序依赖容器创建并注入它所需要的外部资源:而控制反转是 ...
- 自己写的PHP的mql类
用类封装的一个数据库的操作,不仅安全,而且会省去很多代码. header('Content-type:text/html;charset="utf-8"'); class mysq ...
- LeetCode Golang 单向链表相加 反向实现
LeetCode 两数之和, 反向实现 1 -> 2 -> 3 -> 4 + 3 -> 4 ------------------------- ...
- Jquery 过滤器(first,last,not,even,odd)的使用和区别
Jquery 过滤器主要有first,last,not,even,odd等等,它们分别表示: 代码如下: $(function(){ $("#menu li:first").cli ...
- Pyhton学习——Day36
#异步IO——Asynchronous#异步效率最高,特点:全程无阻塞# 在说明synchronous IO和asynchronous IO的区别之前,需要先给出两者的定义.# Stevens给出的定 ...
- PAT 天梯赛练习集 L2-022. 重排链表
题目链接:https://www.patest.cn/contests/gplt/L2-022 给定一个单链表 L1→L2→...→Ln-1→Ln,请编写程序将链表重新排列为 Ln→L1→Ln-1→L ...
- UVA1584-Circular Sequence(紫书例题3.6)
Some DNA sequences exist in circular forms as in the following gure, which shows a circular sequence ...
- 模板 NTT 快速数论变换
NTT裸模板,没什么好解释的 这种高深算法其实也没那么必要知道原理 #include <cstdio> #include <cstring> #include <algo ...