code:
UI_MAINWINDOW_H
/********************************************************************************
** Form generated from reading ui file 'mainwindow.ui'
**
** Created: Wed Sep 1 20:49:39 2010
** by: Qt User Interface Compiler version 4.5.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindowClass
{
public:
QWidget *centralWidget;
QPushButton *pushButton_1;
QPushButton *pushButton_2;
QLineEdit *lineEdit;
QPushButton *pushButton_3;
QPushButton *pushButton_4;
QPushButton *pushButton_5;
QPushButton *pushButton_6;
QPushButton *pushButton_7;
QPushButton *pushButton_8;
QPushButton *pushButton_9;
QPushButton *pushButton_10;
QPushButton *pushButton_11;
QPushButton *pushButton_12;
QPushButton *pushButton_13;
QPushButton *pushButton_14;
QPushButton *pushButton_15;
QPushButton *pushButton;
QPushButton *pushButton_16;
QPushButton *pushButton_17;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindowClass)
{
if (MainWindowClass->objectName().isEmpty())
MainWindowClass->setObjectName(QString::fromUtf8("MainWindowClass"));
MainWindowClass->resize(288, 292);
centralWidget = new QWidget(MainWindowClass);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
pushButton_1 = new QPushButton(centralWidget);
pushButton_1->setObjectName(QString::fromUtf8("pushButton_1"));
pushButton_1->setGeometry(QRect(40, 100, 41, 23));
pushButton_2 = new QPushButton(centralWidget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(100, 100, 41, 23));
lineEdit = new QLineEdit(centralWidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(40, 40, 211, 20));
lineEdit->setMouseTracking(true);
lineEdit->setAcceptDrops(true);
lineEdit->setLayoutDirection(Qt::LeftToRight);
lineEdit->setReadOnly(true);
pushButton_3 = new QPushButton(centralWidget);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
pushButton_3->setGeometry(QRect(160, 100, 41, 23));
pushButton_4 = new QPushButton(centralWidget);
pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
pushButton_4->setGeometry(QRect(220, 100, 41, 23));
pushButton_5 = new QPushButton(centralWidget);
pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
pushButton_5->setGeometry(QRect(40, 130, 41, 23));
pushButton_6 = new QPushButton(centralWidget);
pushButton_6->setObjectName(QString::fromUtf8("pushButton_6"));
pushButton_6->setGeometry(QRect(160, 130, 41, 23));
pushButton_7 = new QPushButton(centralWidget);
pushButton_7->setObjectName(QString::fromUtf8("pushButton_7"));
pushButton_7->setGeometry(QRect(100, 130, 41, 23));
pushButton_8 = new QPushButton(centralWidget);
pushButton_8->setObjectName(QString::fromUtf8("pushButton_8"));
pushButton_8->setGeometry(QRect(220, 130, 41, 23));
pushButton_9 = new QPushButton(centralWidget);
pushButton_9->setObjectName(QString::fromUtf8("pushButton_9"));
pushButton_9->setGeometry(QRect(40, 160, 41, 23));
pushButton_10 = new QPushButton(centralWidget);
pushButton_10->setObjectName(QString::fromUtf8("pushButton_10"));
pushButton_10->setGeometry(QRect(100, 160, 41, 23));
pushButton_11 = new QPushButton(centralWidget);
pushButton_11->setObjectName(QString::fromUtf8("pushButton_11"));
pushButton_11->setGeometry(QRect(160, 160, 41, 23));
pushButton_12 = new QPushButton(centralWidget);
pushButton_12->setObjectName(QString::fromUtf8("pushButton_12"));
pushButton_12->setGeometry(QRect(220, 160, 41, 23));
pushButton_13 = new QPushButton(centralWidget);
pushButton_13->setObjectName(QString::fromUtf8("pushButton_13"));
pushButton_13->setGeometry(QRect(40, 190, 41, 23));
pushButton_14 = new QPushButton(centralWidget);
pushButton_14->setObjectName(QString::fromUtf8("pushButton_14"));
pushButton_14->setGeometry(QRect(100, 190, 41, 23));
pushButton_15 = new QPushButton(centralWidget);
pushButton_15->setObjectName(QString::fromUtf8("pushButton_15"));
pushButton_15->setGeometry(QRect(160, 190, 41, 23));
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(40, 70, 41, 23));
pushButton_16 = new QPushButton(centralWidget);
pushButton_16->setObjectName(QString::fromUtf8("pushButton_16"));
pushButton_16->setGeometry(QRect(220, 190, 41, 23));
pushButton_17 = new QPushButton(centralWidget);
pushButton_17->setObjectName(QString::fromUtf8("pushButton_17"));
pushButton_17->setGeometry(QRect(220, 70, 41, 23));
MainWindowClass->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindowClass);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 288, 24));
MainWindowClass->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindowClass);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindowClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindowClass);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindowClass->setStatusBar(statusBar);
retranslateUi(MainWindowClass);
QMetaObject::connectSlotsByName(MainWindowClass);
} // setupUi
void retranslateUi(QMainWindow *MainWindowClass)
{
MainWindowClass->setWindowTitle(QApplication::translate("MainWindowClass", "MainWindow", 0, QApplication::UnicodeUTF8));
pushButton_1->setText(QApplication::translate("MainWindowClass", "1", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("MainWindowClass", "2", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
lineEdit->setToolTip(QString());
#endif // QT_NO_TOOLTIP
pushButton_3->setText(QApplication::translate("MainWindowClass", "3", 0, QApplication::UnicodeUTF8));
pushButton_4->setText(QApplication::translate("MainWindowClass", "4", 0, QApplication::UnicodeUTF8));
pushButton_5->setText(QApplication::translate("MainWindowClass", "5", 0, QApplication::UnicodeUTF8));
pushButton_6->setText(QApplication::translate("MainWindowClass", "7", 0, QApplication::UnicodeUTF8));
pushButton_7->setText(QApplication::translate("MainWindowClass", "6", 0, QApplication::UnicodeUTF8));
pushButton_8->setText(QApplication::translate("MainWindowClass", "8", 0, QApplication::UnicodeUTF8));
pushButton_9->setText(QApplication::translate("MainWindowClass", "9", 0, QApplication::UnicodeUTF8));
pushButton_10->setText(QApplication::translate("MainWindowClass", "0", 0, QApplication::UnicodeUTF8));
pushButton_11->setText(QApplication::translate("MainWindowClass", "+", 0, QApplication::UnicodeUTF8));
pushButton_12->setText(QApplication::translate("MainWindowClass", "-", 0, QApplication::UnicodeUTF8));
pushButton_13->setText(QApplication::translate("MainWindowClass", "*", 0, QApplication::UnicodeUTF8));
pushButton_14->setText(QApplication::translate("MainWindowClass", "/", 0, QApplication::UnicodeUTF8));
pushButton_15->setText(QApplication::translate("MainWindowClass", "=", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("MainWindowClass", "ce", 0, QApplication::UnicodeUTF8));
pushButton_16->setText(QApplication::translate("MainWindowClass", ".", 0, QApplication::UnicodeUTF8));
pushButton_17->setText(QApplication::translate("MainWindowClass", "+/-", 0, QApplication::UnicodeUTF8));
Q_UNUSED(MainWindowClass);
} // retranslateUi
};
namespace Ui {
class MainWindowClass: public Ui_MainWindowClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindowClass;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
private slots:
void findClicked_1();
void findClicked_2();
void findClicked_3();
void findClicked_4();
void findClicked_5();
void findClicked_6();
void findClicked_7();
void findClicked_8();
void findClicked_9();
void findClicked_0();
void findClicked_jia();
void findClicked_jian();
void findClicked_chen();
void findClicked_chu();
void findClicked_dengyu();
void findClicked_dian();
void findClicked_ce();
void findClicked_fu();
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindowClass *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "string.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
connect(ui->pushButton_1,SIGNAL(clicked()),this,SLOT(findClicked_1()));
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(findClicked_2()));
connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(findClicked_3()));
connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(findClicked_4()));
connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(findClicked_5()));
connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(findClicked_6()));
connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(findClicked_7()));
connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(findClicked_8()));
connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(findClicked_9()));
connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(findClicked_0()));
connect(ui->pushButton_11,SIGNAL(clicked()),this,SLOT(findClicked_jia()));
connect(ui->pushButton_12,SIGNAL(clicked()),this,SLOT(findClicked_jian()));
connect(ui->pushButton_13,SIGNAL(clicked()),this,SLOT(findClicked_chen()));
connect(ui->pushButton_14,SIGNAL(clicked()),this,SLOT(findClicked_chu()));
connect(ui->pushButton_15,SIGNAL(clicked()),this,SLOT(findClicked_dengyu()));
connect(ui->pushButton_16,SIGNAL(clicked()),this,SLOT(findClicked_dian()));
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(findClicked_ce()));
connect(ui->pushButton_17,SIGNAL(clicked()),this,SLOT(findClicked_fu()));
}
QString a,b,c;
QString str1;
QString str2;
QString ss;
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::findClicked_1()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_1->text());
}
void MainWindow::findClicked_2()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_2->text());
}
void MainWindow::findClicked_3()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_3->text());
}
void MainWindow::findClicked_4()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_4->text());
}
void MainWindow::findClicked_5()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_5->text());
}
void MainWindow::findClicked_6()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_6->text());
}
void MainWindow::findClicked_7()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_7->text());
}
void MainWindow::findClicked_8()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_8->text());
}
void MainWindow::findClicked_9()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_9->text());
}
void MainWindow::findClicked_0()
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_10->text());
}
void MainWindow::findClicked_dian()
{
if(ui->lineEdit->text()=="")
{
ui->lineEdit->setText("0.");
}
else
{
if(ui->lineEdit->text().toLocal8Bit().lastIndexOf(".")==-1)
{
ui->lineEdit->setText(ui->lineEdit->text()+ui->pushButton_16->text());
}
}
}
void MainWindow::findClicked_jia()
{
a=ui->lineEdit->text();
b="+";
ui->lineEdit->setText("");
}
void MainWindow::findClicked_jian()
{
a=ui->lineEdit->text();
b="-";
ui->lineEdit->setText("");
}
void MainWindow::findClicked_chen()
{
a=ui->lineEdit->text();
b="*";
ui->lineEdit->setText("");
}
void MainWindow::findClicked_chu()
{
a=ui->lineEdit->text();
b="/";
ui->lineEdit->setText("");
}
void MainWindow::findClicked_dengyu()
{
c=ui->lineEdit->text();
if(a!=""&&b!=""&&c!="")
{
if(b=="+")
{
ss=QString::number(a.toDouble()+c.toDouble());
//ui->lineEdit->setText(QString::number(a.toDouble()+c.toDouble()));
}
if(b=="-")
{
ss=QString::number(a.toDouble()-c.toDouble());
}
if(b=="*")
{
ss=QString::number(a.toDouble()*c.toDouble());
}
if(b=="/")
{
ss=QString::number(a.toDouble()/c.toDouble());
}
//b="/";
ui->lineEdit->setText(ss);
a="";
b="";
}
else
{
ui->lineEdit->setText(ss);
}
}
void MainWindow::findClicked_ce()
{
a="";
b="";
c="";
ui->lineEdit->setText("");
}
void MainWindow::findClicked_fu()
{
if(ui->lineEdit->text().toLocal8Bit().lastIndexOf("-")==-1)
{
str1="-"+ui->lineEdit->text();
}
else
{
str1=""+ui->lineEdit->text().toLocal8Bit().replace("-","");
}
ui->lineEdit->setText(str1);
}
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindowClass</class>
<widget class="QMainWindow" name="MainWindowClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>288</width>
<height>292</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton_1">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>100</x>
<y>100</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>2</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>160</x>
<y>100</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>3</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>220</x>
<y>100</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>4</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_5">
<property name="geometry">
<rect>
<x>40</x>
<y>130</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>5</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_6">
<property name="geometry">
<rect>
<x>160</x>
<y>130</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>7</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_7">
<property name="geometry">
<rect>
<x>100</x>
<y>130</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>6</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_8">
<property name="geometry">
<rect>
<x>220</x>
<y>130</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>8</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_9">
<property name="geometry">
<rect>
<x>40</x>
<y>160</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>9</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_10">
<property name="geometry">
<rect>
<x>100</x>
<y>160</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_11">
<property name="geometry">
<rect>
<x>160</x>
<y>160</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_12">
<property name="geometry">
<rect>
<x>220</x>
<y>160</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_13">
<property name="geometry">
<rect>
<x>40</x>
<y>190</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>*</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_14">
<property name="geometry">
<rect>
<x>100</x>
<y>190</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>/</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_15">
<property name="geometry">
<rect>
<x>160</x>
<y>190</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>=</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>40</x>
<y>70</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>ce</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_16">
<property name="geometry">
<rect>
<x>220</x>
<y>190</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>.</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_17">
<property name="geometry">
<rect>
<x>220</x>
<y>70</y>
<width>41</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>+/-</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>288</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>