1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include "widget.h" #include <QDebug>
Widget::Widget(QWidget *parent) : QWidget(parent) { this->setWindowTitle("信号槽连接方法示例"); this->resize(400, 300);
m_button = new QPushButton("点击计数", this); m_button->setGeometry(150, 130, 100, 40);
connect(m_button, &QPushButton::clicked, this, &Widget::onButtonClicked); }
void Widget::onButtonClicked() { m_count++; QString msg = QString("按钮被点击了 %1 次").arg(m_count);
this->setWindowTitle(msg); qDebug() << msg; }
Widget::~Widget() {}
|