【QT】无需写connect代码关联信号和槽函数

对于一些简单的事件判别,如点击按钮。

无需写代码关联信号和槽函数。

connect(ui->Btnshowhello,SIGNAL(clicked(bool)),this,SLOT(BtnshowhelloSlot()));

信号与槽的自动关联机制。

void on_<object name>_<signal name>(<signal parameters>);

1、UI界面,按钮位置点右键,转到槽。

2、点击后

类似MFC。

void HelloWidget::on_Btnshowhello_clicked()
{
    ui->labelhello->setText("world2");
}

void HelloWidget::on_Btnshowhello_clicked(bool checked)
{
    ui->labelhello->setText("world3");
}

D:EnglishpathQTprojectsuild-untitled2-Desktop_Qt_5_9_3_MinGW_32bit-Debugdebugmoc_hellowidget.cpp


其他:

Qt Creator控件上“转到槽”生成槽函数,源代码中却没发现有connect函数-CSDN论坛 https://bbs.csdn.net/topics/392350040

qt creator如何实现转到槽功能 - 南原始天 - 博客园 https://www.cnblogs.com/wangnan1979/p/4028965.html

qt ui设计界面 创建信号与槽 原理, - GOODDEEP - CSDN博客 https://blog.csdn.net/u013378306/article/details/52431826

Qt信号与槽的自动连接机制:https://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections

BTW: SLOT SIGNAL 是字符串,     &QWidget::pressed 是函数指针

a slot with a name that follows a standard convention:

void on_<object name>_<signal name>(<signal parameters>);

原文地址:https://www.cnblogs.com/wxl845235800/p/10751961.html