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的实战,我写了一个名为<我爱查词典>的词典软件.后来由于导师项目及上课等原因,时间不足,所以该软件的部分功能欠缺,性能有待改善.这学期重新拿出来看时,又有很多东 ...
随机推荐
- v-cli环境的安装
第一步:node npm是node的包管理器 yarn 第二步:npm install -g vue-cli或者淘宝镜像 如果安装失败:在node.js com ...
- filezilla的root账户无法连接服务器解决办法
lz一直都是用filezilla上传文件到vm虚拟机的,用的是ubuntu14.04的系统.最近自己重新搭了lamp去做thinkphp的学习,lz有两个账户,一个是kin,另外一个是root.大家都 ...
- POJ 3185 DFS
好像可以用高斯消元??? 但是用搜索写 这题就很水了... // by SiriusRen #include <bitset> #include <cstdio> using ...
- JQuery学习系列篇(一)
jQuery是一套Javascript脚本库:注意jQuery是脚本库, 而不是脚本框架. "库"不等于"框架", 比如"System程序集" ...
- stackoverflow 加载特慢解决方案,配置 hosts 屏蔽速度慢的第三方 API
127.0.0.1 ajax.googleapis.com www.googletagservices.com www.gravatar.com 127.0.0.1 securepubads.g.do ...
- 开源UWP总结
1.UWP第三方简书客户端分享:http://www.cnblogs.com/youngytj/p/4889010.html 2.知乎日报:http://www.cnblogs.com/xiaozhi ...
- Android 网络状态变化的监听
1.在流量网页,时实现断网,提醒等功能. 需要权限 <uses-permission android:name="android.permission.INTERNET"/& ...
- Android中onActivityResult()获取返回值
需求:从FirstActivity跳到SecondActivity,在SecondActivity中进行了操作并返回到FirstActivity. FirstActivity中的主要代码: priva ...
- 11 个使用 GNOME 3 桌面环境的理由
11 个使用 GNOME 3 桌面环境的理由 作者: David Both 译者: LCTT geekpi | 2017-08-22 11:43 评论: 27 GNOME 3 桌面的设计目的是简单 ...
- Windows系统Python环境搭建
Python下载 下载地址:https://www.python.org/downloads/ 选择需要下载的版本 以Python3.3.7版本为例,下载64位和32位都分别有三种方式,依次是压缩包, ...