赞
踩
1、首先使用qcreator编辑界面,如下:
2、然后保存这个界面:add.ui
3、利用
qmake -project
qmake
make
其中可能出现错误,但是没有关系。主要是产生ui_Add.h这样一个头文件
4、建立三个文件
(1)Add.h内容如下:
#ifndef Add_H_H
#define Add_H_H
#include <QObject>
#include <QDialog>
#include "ui_Add.h"
class AddDlg:public QDialog,public Ui_AddDlg
{
Q_OBJECT
public:
AddDlg(QWidget *parent = 0 );
~AddDlg();
public slots:
void sum();
signals:
};
#endif
(2)Add.cpp
#include"QtGui"
#include <QDialog>
#include <QWidget>
#include <QDebug>
#include "Add.h"
#include "ui_Add.h"
AddDlg::AddDlg(QWidget *parent):QDialog(parent)
{
setupUi(this);
qDebug() << "Date:" ;
connect(pBAdd,SIGNAL(clicked()),this,SLOT(sum()));
}
void AddDlg::sum()
{
QString str1 = Num1->text();
QString str2 = Num2->text();
double a,b,c;
a = str1.toDouble();
b = str2.toDouble();
c = a+b;
//QString ss = "nnn";
Sum->setText(QString::number(c));
//Sum->setText(ss);
//pBAdd->setText("ok");
}
AddDlg::~AddDlg()
{
}
(3)main.cpp
#include <QApplication>
#include <QDialog>
#include "ui_Add.h"
#include "Add.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
Ui::AddDlg ui;
//AddDlg *dlg = new AddDlg;
//ui.setupUi(dlg);
AddDlg dlg;
dlg.show();
return app.exec();
}
5、然后执行下列命令即可
qmake -project
qmake
make
运行程序即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。