Qt connectSlotsByName(QObject *)

1868 ワード


 
uiファイルを編集するときにスロット関数を使用できます.on_objectName_signal(args) ; 非常に簡単で、ドキュメントの説明は次のとおりです.
 
1 void QMetaObject::connectSlotsByName ( QObject * object ) [static]
2 Searches recursively for all child objects of the given object, and connects matching signals from them to slots of object that follow the following form:
3 
4 void on_<object name>_();
5 Let's assume our object has a child object of type QPushButton with the object name button1. The slot to catch the button's clicked() signal would be:
6 
7 void on_button1_clicked(); 

ここでbutton 1はuiオブジェクトの下にあるが、システムが自動的に接続を確立したことに相当する.
それはMainWindowに等しい.cpp中:connect(ui->button 1,&QpushButton::clicked,this,on_button 1_clicked);
 
——————————————————著作権声明:本文はCSDNブロガー「liulihuo_gyh」のオリジナル文章で、CC 4.0 BY-SA著作権協定に従い、原文の出典リンクと本声明を転載してください.テキストリンク:https://blog.csdn.net/liulihuo_gyh/article/details/45535675