[PyQt] QMetaObject::Connection equivalent

Florian Bruhin me at the-compiler.org
Wed Mar 2 15:09:28 GMT 2016


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?

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160302/4dbd82c4/attachment.sig>


More information about the PyQt mailing list