安装qt5.5的VS2010插件,开发方式和VC差不多,不过底层支持库由MFC转换为Qt库。
用向导生成一个窗口。使用qt设计师在窗口上放上一个按钮。
.h文件内容如下:
#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()));
此句由设计师自动产生,用来指定按钮点击时的响应动作。
pushButton:是信号发送者
clicked() :是发送信号
testClass :是当前窗口类,也就是接收者
btn_OnClicked():是槽函数
转载于:https://blog.51cto.com/9233403/1967673