先看Qt Assistant中对connectSlotsByName 函数的说明:
void QMetaObject::connectSlotsByName ( QObject * object ) [static]
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:
void on_<widget name>_<signal name>(<signal parameters>); //响应槽的函数原型
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:
void on_button1_clicked();
该函数在界面开发工具(Qt Designer或者vs2005)中,自动的在setupUi()函数中调用,使得所编辑的GUI的内部挂件自动的connect信号和相应的函数。但是要注意不要忘记在包含该框架的类中定义槽void on_<widget name>_<signal name>(<signal parameters>);
void QMetaObject::connectSlotsByName ( QObject * object ) [static]
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:
void on_<widget name>_<signal name>(<signal parameters>); //响应槽的函数原型
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:
void on_button1_clicked();
该函数在界面开发工具(Qt Designer或者vs2005)中,自动的在setupUi()函数中调用,使得所编辑的GUI的内部挂件自动的connect信号和相应的函数。但是要注意不要忘记在包含该框架的类中定义槽void on_<widget name>_<signal name>(<signal parameters>);
Qt中connectSlotsByName详解
本文详细介绍了Qt中connectSlotsByName函数的工作原理及其使用方法。该函数能够递归搜索指定对象的所有子对象,并将匹配的信号连接到遵循特定命名规则的槽函数。文章还提到了在QtDesigner等界面开发工具中如何自动调用此函数来实现GUI组件的信号与槽的自动连接。
760

被折叠的 条评论
为什么被折叠?



