[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    PyQt5 signal connection with a receiver context object?
From:       Jeremy Katz <jkatz () volexity ! com>
Date:       2020-11-14 7:24:54
Message-ID: e091f534-347b-c886-31a9-a6968c8e926b () volexity ! com
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]

[Attachment #4 (multipart/mixed)]


Hi,

Is there a PyQt equivalent to this version of QObject::connect?

static QMetaObject::Connection QObject::connect(
    const QObject *sender,
    PointerToMemberFunction signal,
    const QObject *context,
    Functor functor,
    Qt::ConnectionType type)

https://doc.qt.io/qt-5/qobject.html#connect-5

The appeal of this version for a lambda slot is:
* automatic disconnection if sender or context are destroyed
* slot invocation according to context's thread and the connection type

My use case is connecting to lambda slots that capture a QObject.

For example:
    obj1 = QObject()
    obj2 = QObject()
    obj1.destroyed.connect(lambda: print("scheduling obj2 deletion") or
                                   obj2.deleteLater())
    del obj2
    del obj1
    scheduling obj2 deletion
    Traceback (most recent call last):
    File "<stdin>", line 2, in <lambda>
    NameError: name 'obj2' is not defined
    Abort trap: 6

["OpenPGP_0x095F4F2148BF111D.asc" (application/pgp-keys)]
["OpenPGP_signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic