QT 信号与槽

 .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);
}

现象

相关推荐

  1. qt-信号

    2024-01-11 18:14:02       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-11 18:14:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-11 18:14:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-11 18:14:02       82 阅读
  4. Python语言-面向对象

    2024-01-11 18:14:02       91 阅读

热门阅读

  1. 【5种常见的rpc封装方案】

    2024-01-11 18:14:02       50 阅读
  2. vue安装

    vue安装

    2024-01-11 18:14:02      52 阅读
  3. 使用Docker运行SRS Stack

    2024-01-11 18:14:02       66 阅读
  4. 实现本地存储函数useLocalStorage

    2024-01-11 18:14:02       67 阅读
  5. bool和BOOL的区别

    2024-01-11 18:14:02       46 阅读
  6. LLaMA Efficient Tuning

    2024-01-11 18:14:02       53 阅读
  7. Redis的基本命令和数据类型

    2024-01-11 18:14:02       55 阅读
  8. QT第1天

    QT第1天

    2024-01-11 18:14:02      58 阅读
  9. 合泰HT32F65C40F 串口驱动 例:UART0 数据收发

    2024-01-11 18:14:02       65 阅读