?.h文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
public slots:
void buttonLable();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
.cpp文件
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
int i = 1;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL( clicked()) , this, SLOT(buttonLable()));
connect(ui->pushButton_2, SIGNAL( clicked()) , this, SLOT(buttonLable()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::buttonLable()
{
qDebug()<<"void buttonLable()";
QString str = QString("此按键点击了 %1 次").arg(i++);
this->ui->label->setText(str);
}
现象