在QML中,不可能在没有信号参数的情况下调用.disconnect():

file:mainwindow.qml:107: Error: Function.prototype.disconnect: no arguments given

那么,如何在不指定所有插槽的情况下断开所有插槽的连接?
或者,也许可以通过将信号对象传递到C++并以某种方式断开它的连接来实现?
也许存在任何解决方法?

我要达到的目标是通过将不同的插槽连接到其信号来更改其行为。例如:
object.disconnect() // disconnect all slots
object.connect(one_super_slot)
object.disconnect() // disconnect all slots
object.connect(another_super_slot)

最佳答案

否。我查看了qv4objectwrapper.cpp中的源代码,您可以看到以下代码:

void QObjectWrapper::initializeBindings(ExecutionEngine *engine)
{
    engine->functionClass->prototype->defineDefaultProperty(QStringLiteral("connect"), method_connect);
    engine->functionClass->prototype->defineDefaultProperty(QStringLiteral("disconnect"), method_disconnect);
}

这些是仅添加的两种方法。如果查看method_disconnect()的源代码,您会发现它始终需要一个或两个参数,包括要断开连接的插槽的名称。

很遗憾,没有disconnectAll()

关于qt - 是否可以从Qt5 QML中的信号断开所有插槽?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27571951/

10-11 11:41