QSocketNotifier

PyQt5.QtCore.QSocketNotifier

Inherits from QObject.

Description

The QSocketNotifier class provides support for monitoring activity on a file descriptor.

The QSocketNotifier makes it possible to integrate Qt’s event loop with other event loops based on file descriptors. File descriptor action is detected in Qt’s main event loop (exec()).

Once you have opened a device using a low-level (usually platform-specific) API, you can create a socket notifier to monitor the file descriptor. The socket notifier is enabled by default, i.e. it emits the activated signal whenever a socket event corresponding to its type occurs. Connect the activated signal to the slot you want to be called when an event corresponding to your socket notifier’s type occurs.

There are three types of socket notifiers: read, write, and exception. The type is described by the Type enum, and must be specified when constructing the socket notifier. After construction it can be determined using the type() function. Note that if you need to monitor both reads and writes for the same file descriptor, you must create two socket notifiers. Note also that it is not possible to install two socket notifiers of the same type (Read, Write, Exception) on the same socket.

The setEnabled() function allows you to disable as well as enable the socket notifier. It is generally advisable to explicitly enable or disable the socket notifier, especially for write notifiers. A disabled notifier ignores socket events (the same effect as not creating the socket notifier). Use the isEnabled() function to determine the notifier’s current status.

Finally, you can use the socket() function to retrieve the socket identifier. Although the class is called QSocketNotifier, it is normally used for other types of devices than sockets. QTcpSocket and QUdpSocket provide notification through signals, so there is normally no need to use a QSocketNotifier on them.

Enums

Type

This enum describes the various types of events that a socket notifier can recognize. The type must be specified when constructing the socket notifier.

Note that if you need to monitor both reads and writes for the same file descriptor, you must create two socket notifiers. Note also that it is not possible to install two socket notifiers of the same type (Read, Write, Exception) on the same socket.

See also

QSocketNotifier, type().

Member

Value

Description

Exception

2

An exception has occurred. We recommend against using this.

Read

0

There is data to be read.

Write

1

Data can be written.

Methods

__init__(sip.voidptr, Type, parent: QObject = None)

TODO


event(QEvent) → bool

TODO


isEnabled() → bool

Returns true if the notifier is enabled; otherwise returns false.

See also

setEnabled().


setEnabled(bool)

If enable is true, the notifier is enabled; otherwise the notifier is disabled.

The notifier is enabled by default, i.e. it emits the activated signal whenever a socket event corresponding to its type() occurs. If it is disabled, it ignores socket events (the same effect as not creating the socket notifier).

Write notifiers should normally be disabled immediately after the activated signal has been emitted

See also

isEnabled(), activated.


socket() → sip.voidptr

Returns the socket identifier specified to the constructor.

See also

type().


type() → Type

Returns the socket event type specified to the constructor.

See also

socket().

Signals

activated(int)

TODO