對於一些簡單的事件判別,如點擊按鈕。
無需寫代碼關聯信號和槽函數。
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:\Englishpath\QTprojects\build-untitled2-Desktop_Qt_5_9_3_MinGW_32bit-Debug\debug\moc_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>);