Deprecated QScoketNotifier::activated signal overload
Phil Thompson
phil at riverbankcomputing.com
Mon Mar 20 16:21:46 GMT 2023
On 17/03/2023 17:36, Florian Bruhin wrote:
> Hey,
>
> When connecting to a QSocketNotifier's activated signal, it looks like
> PyQt insists on using the deprecated variant:
>
> QSocketNotifier::activated(int socket)
> https://doc.qt.io/qt-6/qsocketnotifier-obsolete.html#activated-1
>
> Rather than using the new replacement (since Qt 5.15):
>
> QSocketNotifier::activated(QSocketDescriptor socket,
> QSocketNotifier::Type type)
> https://doc.qt.io/qt-6/qsocketnotifier.html#activated
>
> Example:
>
> ---------------------------------------------------------------------
>
> import os, sys
> from PyQt6.QtCore import QSocketNotifier, QCoreApplication, pyqtSlot
>
> # @pyqtSlot("QSocketDescriptor", "QSocketNotifier::Type")
> def on_notifier_activated(socket, typ):
> print(type(socket), socket)
> print(type(typ), typ)
>
> app = QCoreApplication(sys.argv)
> reader, writer = os.pipe()
> notifier = QSocketNotifier(reader, QSocketNotifier.Type.Read)
> notifier.activated.connect(on_notifier_activated)
> os.write(writer, b"x")
> app.exec()
>
> ---------------------------------------------------------------------
>
> Without the @pyqtSlot, this leads to:
>
> qt.core.qobject.connect: QObject::connect: Connecting from COMPAT
> signal (QSocketNotifier::activated(int))
> TypeError: on_notifier_activated() missing 1 required positional
> argument: 'typ'
>
> (first line with Qt debug build only).
>
> With the @pyqtSlot, instead:
>
> Traceback (most recent call last):
> File "/home/florian/tmp/test.py", line 4, in <module>
> @pyqtSlot("QSocketDescriptor", "QSocketNotifier::Type")
> TypeError: C++ type 'QSocketDescriptor' is not supported as a pyqtSlot
> argument type
I didn't implement the newer signal because of the undocumented
QSocketDescriptor class. I have a general rule that if something isn't
documented then it's not part of the public API. Why specify
QSocketDescriptor when QSocketNotifier uses qintptr to represent a
socket? The whole thing had a bad smell.
Is the loss of the second argument a problem?
Phil
More information about the PyQt
mailing list