Qt connectSlotsByName(QObject *)(转)

我们编辑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>_<signal name>(<signal parameters>);
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(); 

尽管这里的button1是ui对象下的,它也是可以这样使用的,相当于系统自动建立好了连接。

它等同于在MainWindow。cpp中:connect(ui->button1, &QPushButton ::clicked, this, on_button1_clicked);

————————————————
版权声明:本文为CSDN博主「liulihuo_gyh」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liulihuo_gyh/article/details/45535675

原文地址:https://www.cnblogs.com/Stephen-Qin/p/13149507.html