打电话有效吗
QObject::connect(a, SIGNAL(somesig(someparam)), b, SLOT(someslot()));
没有参数?它似乎有效(没有抛出运行时异常),但我在文档中找不到引用。我发现如果 someslot 有默认参数,这是可能的。在这种情况下它是有效的。但是我的方法 someslot 没有与默认设置相同的参数(示例中没有参数)。
那么似乎可以将信号连接到参数较少的插槽?
最佳答案
是的,没关系。在 Signals & Slots 中有一个关于它的简短句子文档:
[...] The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.) [...]
在页面下方甚至还有一个类似的示例,其中解释了默认参数。
关于qt - 将信号连接到 Qt 中允许的参数较少的插槽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18388283/