ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:322.45KB ,
资源ID:8218153      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8218153.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Qt计算器.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Qt计算器.docx

1、Qt计算器 Linux界面设计Qt简单计算器课程名称:计算机基础综合 课题分类:Qt界面设计 班 级:11计算机科学与技术2班姓 名:段秉芮 学 号:1145532211 完成时间:2014年01月01Qt计算器一.摘要当今社会是信息社会,科技经济高速发展的社会,为了更方便人们的工作生活和加速人们处理信息的速度,计算器应运而生。然而,电脑已经成为当代人生活的必需品,运行在电脑上的计算器成为了人们的生活学习绝佳伴侣。本设计是用C+编写的,基于Qt图形用户界面应用程序框架的计算器。设计出两个电脑端和安卓手机端两个应用程序,并实现了一定的计算功能。二建立项目如下所示: 首先在linux下softce

2、nter安装Qt Creator 或者在terminal中输入命令安装; sudo apt-get install libqt4-dev libqt4-debug libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig比如qt4-dev-tools 包含了Qt Assistant及Qt Linguist等工具,因此不需要单独安装这两个工具。其它的,qt4-doc 是帮助文档,包含了Qt中各个类库的详细说明以及丰富的例子程序,可以使用Qt Assistant 工具来打开阅读。qt4-qtconfig 是配置Qt环

3、境的一个对话框,一般默认就行了,很少有必要去更改。qt4-demos 包含很多可以运行起来的可执行文件以及源代码。qt4-designer是用来设计GUI界面的设计器 sudo apt-get install libqt4-debug /sudo apt-get install libqt4-dbg安装完成打开。1.创建工程选择File-NewFileorProject,然后如下所示,之后next。之后在Details时候,选项Base class选中QWidget。然后next至finish。二程序代码如下:1.建立calculator.h右键calculator项目,选择add new。如

4、下所示:calculator.h代码修改如下:#ifndef CALCULATOR_H#define CALCULATOR_H#include#include#include#includeclass Calculator : public QWidget Q_OBJECTpublic: Calculator(QWidget *parent = 0); Calculator();private: QTextEdit* screenTextEdit; QPushButton* button1; QPushButton* button2; QPushButton* button3; QPushBu

5、tton* button4; QPushButton* button5; QPushButton* button6; QPushButton* button7; QPushButton* button8; QPushButton* button9; QPushButton* button0; QPushButton* buttonx; QPushButton* buttondivide; QPushButton* buttonadd; QPushButton* buttonsub; QPushButton* buttondot; QPushButton* buttonequal; QPushB

6、utton* buttonclear; QPushButton* buttonback; QPushButton* buttonLArc; QPushButton* buttonRArc; bool isEnter; double sum ; int i; int j; double result; bool isPoint; bool isLArc; char sign; bool isTwoOptrsFlag; bool isEqualClicked; int f17; int f27; QVectorvectorOpnd; QVectorvectorOptr; QVectorvector

7、Exp; bool isTwoOptr(QPushButton *button); void initConnect(); void initVector(); double operate(double a, char theat, double b); char precedeSign(char optr1, char optr2); int char2num(char optr); void initData(); char button2char(QPushButton *button); void getDigital(char digital); void getSign(char

8、 ch); bool pickSign(char ch); bool pushVector(char optr); void getResult();private slots: void getButton(); void clearScreen(); void myBackSpace();#endif / CALCULATOR_H2.main.cpp修改如下: 只需要将Widget w;w.show(); 修改为Calculator cal; cal.show(); 3.calculator.cpp 建立calculator.cpp文件的过程和建立calculator.h的过程一样,只是选

9、择C+ Source File选项。 calculator.cpp代码如下:#include calculator.h#includeCalculator:Calculator(QWidget *parent) : QWidget(parent) initData(); setWindowTitle(计算器); setWindowIcon(QIcon(:/calculator.png); screenTextEdit = new QTextEdit; screenTextEdit-setFixedHeight(50); screenTextEdit-setFont(QFont(Courier

10、10 Pitch, 18, QFont:Bold); screenTextEdit-setReadOnly(true); button1 = new QPushButton(1); button2 = new QPushButton(2); button3 = new QPushButton(3); button4 = new QPushButton(4); button5 = new QPushButton(5); button6 = new QPushButton(6); button7 = new QPushButton(7); button8 = new QPushButton(8);

11、 button9 = new QPushButton(9); button0 = new QPushButton(0); buttonx = new QPushButton(); buttonadd = new QPushButton(+); buttonsub = new QPushButton(-); buttonback = new QPushButton(back); buttondivide = new QPushButton(/); buttondot = new QPushButton(.); buttonLArc = new QPushButton(); buttonRArc

12、= new QPushButton(); buttonequal = new QPushButton(=); buttonclear = new QPushButton(clear); initConnect(); QGridLayout *gridLayout = new QGridLayout; gridLayout-addWidget(screenTextEdit, 0, 0, 2, 5); gridLayout-addWidget(button1, 2, 0, 1, 1); gridLayout-addWidget(button2, 2, 1, 1 ,1); gridLayout-ad

13、dWidget(button3, 2, 2, 1, 1); gridLayout-addWidget(buttonadd, 2, 3, 1, 1); gridLayout-addWidget(buttonsub, 2, 4, 1, 1); gridLayout-addWidget(button4, 3, 0, 1, 1); gridLayout-addWidget(button5, 3, 1, 1, 1); gridLayout-addWidget(button6, 3, 2, 1, 1); gridLayout-addWidget(buttonx, 3, 3, 1, 1); gridLayo

14、ut-addWidget(buttondivide, 3, 4, 1, 1); gridLayout-addWidget(button7, 4, 0, 1, 1); gridLayout-addWidget(button8, 4, 1, 1, 1); gridLayout-addWidget(button9, 4, 2, 1, 1); gridLayout-addWidget(buttonLArc, 4, 3, 1, 1); gridLayout-addWidget(buttonRArc, 4, 4, 1, 1); gridLayout-addWidget(button0, 5, 0, 1,

15、1); gridLayout-addWidget(buttondot, 5, 1, 1, 1); gridLayout-addWidget(buttonback, 5, 2, 1, 1); gridLayout-addWidget(buttonclear, 5, 3, 1, 1); gridLayout-addWidget(buttonequal, 5, 4, 1, 1); setLayout(gridLayout); initVector();void Calculator:initConnect() connect(button0, &QPushButton:clicked, this,

16、&Calculator:getButton); connect(button1, &QPushButton:clicked, this, &Calculator:getButton); connect(button2, &QPushButton:clicked, this, &Calculator:getButton); connect(button3, &QPushButton:clicked, this, &Calculator:getButton); connect(button4, &QPushButton:clicked, this, &Calculator:getButton);

17、connect(button5, &QPushButton:clicked, this, &Calculator:getButton); connect(button6, &QPushButton:clicked, this, &Calculator:getButton); connect(button7, &QPushButton:clicked, this, &Calculator:getButton); connect(button8, &QPushButton:clicked, this, &Calculator:getButton); connect(button9, &QPushB

18、utton:clicked, this, &Calculator:getButton); connect(buttonx, &QPushButton:clicked, this, &Calculator:getButton); connect(buttonadd, &QPushButton:clicked, this, &Calculator:getButton); connect(buttondivide, &QPushButton:clicked, this, &Calculator:getButton); connect(buttondot, &QPushButton:clicked,

19、this, &Calculator:getButton); connect(buttonsub, &QPushButton:clicked, this, &Calculator:getButton); connect(buttonRArc, &QPushButton:clicked, this, &Calculator:getButton); connect(buttonLArc, &QPushButton:clicked, this, &Calculator:getButton); connect(buttonback, &QPushButton:clicked, this, &Calcul

20、ator:myBackSpace); connect(buttonclear, &QPushButton:clicked, this, &Calculator:clearScreen); connect(buttonequal, &QPushButton:clicked, this, &Calculator:getButton);bool Calculator:isTwoOptr(QPushButton *button) if(button = buttonadd | button =buttonsub | button = buttonx | button = buttondivide) r

21、eturn true; else return false;void Calculator:myBackSpace() QTextCursor cursor = screenTextEdit-textCursor(); cursor.deletePreviousChar(); if(!isEqualClicked) vectorExp.pop_back();void Calculator:getButton() QPushButton* button = qobject_cast(sender(); if(isTwoOptrsFlag & isTwoOptr(button) else vect

22、orExp.append(button2char(button); isEqualClicked = false; isTwoOptrsFlag = false; if(!isEnter) screenTextEdit-append(); screenTextEdit-insertPlainText(button-text(); isEnter = true; if(button = buttonadd | button = buttonsub | button = buttonx | button = buttondivide) isTwoOptrsFlag = true; if(butto

23、n = buttonequal) isEqualClicked = true; getResult(); void Calculator:getResult() while(!vectorExp.isEmpty() char ch = vectorExp.first(); vectorExp.removeFirst(); getDigital(ch); getSign(ch); void Calculator:getDigital(char digital) if(digital = 0 | digital = 1 | digital = 2 | digital = 3 | digital =

24、 4 | digital = 5 | digital = 6 | digital = 7 | digital = 8 | digital = 9 ) if(isPoint) i *= 10; j = 0; sum = sum * 10 + (digital - 0); isLArc = false; else if(digital = .) isPoint = true; isLArc = false; void Calculator:getSign(char ch) if(isLArc & ch != ( & ch != ) sign = ch; else if(ch = + | ch =

25、- | ch = * | ch = / | ch = = | ch = ( | ch = ) if(ch = () isLArc = true; else isLArc = false; j+; if(j insertPlainText(QString(%1).arg(result); vectorOpnd.clear(); vectorOptr.clear(); initVector(); isEnter = false; return true; pushVector(ch); return true;bool Calculator:pushVector(char optr) char t

26、heta; double a, b; if(optr = ) do theta = vectorOptr.last(); vectorOptr.pop_back(); while(theta = ( | theta = ); if(theta != #)/ void 8(,9),8() b = vectorOpnd.last();vectorOpnd.pop_back(); a = vectorOpnd.last();vectorOpnd.pop_back(); vectorOpnd.append(operate(a, theta, b); else vectorOptr.append(#); return true; switch(precedeSign(vectorOptr.last(),optr) case : theta = vectorOptr.last(); vectorOptr.pop_back(); b = vectorOpnd.last(); vectorOpnd.pop_back(); a = vectorOpnd.last(); vectorOpnd.pop_back(); vectorOpnd.append(operate(a, theta, b); vectorOptr.append(optr); break; return true;vo

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1