在阅读obs-studio源码时候,发现好多槽函数并没有通过connect方法绑定到某个信号上,一直很疑惑。继续阅读源码才发现,是利用了Qt中通过约定信号槽命名的方式实现的绑定。
即通过QMetaObject::connectSlotsByName(this);实现。
官方文档中的解释如下:
[static] void QMetaObject::connectSlotsByName(QObject *object)
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_<object 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();
If object itself has a properly set object name, its own signals are also connected to its respective slots.
很简单的英文。