QT周三作业

1.题目:点击按钮改变文字
代码:
1.widget.h
//widget.h
 
#ifndef WIDGET_H
#define WIDGET_H
 
#include 
 
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
 
class Widget : public QWidget    //窗体对象
{
    Q_OBJECT
 
public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    int count;    //计数
 
public slots:
    void pushBtn(void);    //接收槽
 
private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
2.widget.cpp
//widget.cpp
 
#include "widget.h"
#include "ui_widget.h"
#include 
 
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    count=0;    //初始化count
 
    //绑定信号与接收槽
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(pushBtn()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(pushBtn()));
}
 
Widget::~Widget()
{
    delete ui;
}
 
void Widget::pushBtn()
{
    count++;
//    qDebug()<<"count="<label->setText(str);
 
}

你可能感兴趣的:(qt,开发语言)