[PyQt] QMetaObject::Connection equivalent
Phil Thompson
phil at riverbankcomputing.com
Wed Jun 6 17:23:16 BST 2018
On 2 Mar 2016, at 3:09 pm, Florian Bruhin <me at the-compiler.org> wrote:
>
> Hi,
>
> I just noticed Qt5 returns a QMetaObject::Connection object when using
> QObject::connect:
>
> http://doc.qt.io/qt-5/qobject.html#connect-2
> http://doc.qt.io/qt-5/qmetaobject-connection.html
>
> You can then use that with the appropriate QObject::disconnect method
> to disconnect e.g. lambdas easily again:
>
> http://doc.qt.io/qt-5/qobject.html#disconnect-4
>
> I'm missing something like that in Python - it'd be nice to be able to
> do something like this:
>
> w = QTextEdit()
> connection = w.textChanged.connect(lambda text: None)
> # [...]
> w.textChanged.disconnect(connection)
>
> 'connection' then would be some pyqtSignalConnection object which
> pyqtSignal.disconnect understands.
>
> Alternatively (or in addition to the above), disconnect could be a
> method of pyqtSignalConnection:
>
> w = QTextEdit()
> connection = w.textChanged.connect(lambda text: None)
> # [...]
> connection.disconnect()
>
> This would make it easier to work with Python lambda's and
> pyqtSignals.
>
> What do you think?
I don't know I've had a blind spot about this...
QMetaObject.Connection is now wrapped, is returned by connect() and can be passed to disconnect().
...in tonight's snapshot.
Phil
More information about the PyQt
mailing list