Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disconnect all slots from a signal in Qt5 QML?

In QML it is impossible to call .disconnect() without arguments for a signal:

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

So how can I disconnect ALL slots without specifying each of them? Or maybe it is possible by passing signal object to C++ and disconnect it somehow there? Or maybe any workaround exists?

The goal I want to reach is to change behavior of an object by connecting different slots to it's signal. For example:

object.disconnect() // disconnect all slots
object.connect(one_super_slot)
object.disconnect() // disconnect all slots
object.connect(another_super_slot)
like image 587
Victor Polevoy Avatar asked Dec 19 '14 18:12

Victor Polevoy


1 Answers

No. I looked at the source code in qv4objectwrapper.cpp, and you can see this code:

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

Those are the only two methods that are added. If you look at the source code for method_disconnect() you can see that it always requires one or two parameters, including the name of the slot to disconnect.

There is no disconnectAll() unfortunately.

like image 148
Timmmm Avatar answered Nov 15 '22 09:11

Timmmm