#ifndef TEST_H
#define TEST_H
#include <QtWidgets/QMainWindow>
#include "ui_test.h"
class test : public QMainWindow
{
Q_OBJECT
public:
test(QWidget *parent = 0);
~test();
private:
Ui::testClass ui;//界面管理类
public slots:
void btn_OnClicked();//手动添加的槽函数
};
#endif // TEST_H
.cpp文件内容如下:
#include "stdafx.h"
#include "test.h"
test::test(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
test::~test()
{
}
void test::btn_OnClicked()//手动编写的
{
QString str = this->ui.lineEdit->text();
QMessageBox::information(this,QString("提示"), str, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
在Qt设计师中指定槽函数。在ui_test.h文件中,将会自动产生如下语句:
QObject::connect(pushButton, SIGNAL(clicked()), testClass, SLOT(btn_OnClicked()));
此句由设计师产生,也可手动添加