QT 1.10

QT 1.10_第1张图片

点击任意按钮让label中显示的次数加1

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->label->setText(QString("你点击了%1次.").arg(this->x));
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(pushButton_clicked()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(pushButton_2_clicked()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(pushButton_3_clicked()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(pushButton_4_clicked()));

}

Widget::~Widget()
{
    delete ui;
}


void Widget::pushButton_clicked()
{
    this->x++;
    this->ui->label->setText(QString("你点击了%1次.").arg(this->x));
}

void Widget::pushButton_2_clicked()
{
    this->x++;
    this->ui->label->setText(QString("你点击了%1次.").arg(this->x));
}

void Widget::pushButton_3_clicked()
{
    this->x++;
    this->ui->label->setText(QString("你点击了%1次.").arg(this->x));
}

void Widget::pushButton_4_clicked()
{
    this->x++;
    this->ui->label->setText(QString("你点击了%1次.").arg(this->x));
}

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include 
#include "signalandslot.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    int x=0;


private slots:
    void pushButton_clicked();

    void pushButton_2_clicked();

    void pushButton_3_clicked();

    void pushButton_4_clicked();

private:
    Ui::Widget *ui;

};
#endif // WIDGET_H

ui

QT 1.10_第2张图片

你可能感兴趣的:(qt)