求Qt执行类似a+b的代码
各位大侠帮帮忙,老师要求我做一个程序(图形化的界面),我就想用Qt来实现;
但由于我知识有限,时间很赶,没办法看完Qt 的教程,希望各位帮帮忙写一下代码,让我学习一下
有两个输入框,还有一个确定的按钮,输入两个数字,点确定,弹出两个数字的和~~~谢谢啦!!感激不尽~~!!!
[解决办法]
你很幸运,我今天刚看完了Qt,而且你说的都是是简单的东西!不过看到你的结贴率之后我发现,我什么也不能说了!如果非常想要可以加我的Q:571001994
[解决办法]
我来灌个水~~
//mainwindow.h:#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QtGui>class MainWindow : public QWidget{ Q_OBJECTpublic: MainWindow(QWidget * parent = 0); ~MainWindow();private slots: void doAdd();private: QLineEdit *txtA, *txtB; QPushButton *btnAdd; QMessageBox *msgBox;};#endif // MAINWINDOW_H//mainwindow.cpp:#include "mainwindow.h"MainWindow::MainWindow(QWidget * parent) : QWidget(parent){ txtA = new QLineEdit; txtB = new QLineEdit; btnAdd = new QPushButton("add"); QHBoxLayout * layoutUpper = new QHBoxLayout; QVBoxLayout * mainLayout = new QVBoxLayout; msgBox = new QMessageBox; layoutUpper->addWidget(txtA); layoutUpper->addWidget(txtB); mainLayout->addLayout(layoutUpper); mainLayout->addWidget(btnAdd); connect(btnAdd, SIGNAL(clicked()), this, SLOT(doAdd())); this->setLayout(mainLayout);}MainWindow::~MainWindow(){}void MainWindow::doAdd(){ int sum = txtA->text().toInt() + txtB->text().toInt(); msgBox->setText(QString::number(sum)); msgBox->show();}//main.cpp:#include <QtCore>#include "mainwindow.h"int main(int argc, char* argv[]){ QApplication app(argc, argv); MainWindow window; window.show(); return app.exec();}
[解决办法]
我觉得LZ还是自己实现比较好。。。