QSocketNotifier¶
The
QSocketNotifier
class provides support for monitoring activity on a file descriptor. More…
Synopsis¶
Functions¶
Slots¶
def
setEnabled
(arg__1)
Detailed Description¶
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 theactivated()
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 thetype()
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 theisEnabled()
function to determine the notifier’s current status.Finally, you can use the
socket()
function to retrieve the socket identifier. Although the class is calledQSocketNotifier
, it is normally used for other types of devices than sockets.QTcpSocket
andQUdpSocket
provide notification through signals, so there is normally no need to use aQSocketNotifier
on them.
- class PySide2.QtCore.QSocketNotifier(arg__1, arg__2[, parent=None])¶
PySide2.QtCore.QSocketNotifier(socket, arg__2[, parent=None])
- param parent:
- param arg__1:
object
- param socket:
qintptr
- param arg__2:
Constructs a socket notifier with the given
parent
. It enables thesocket
, and watches for events of the giventype
.It is generally advisable to explicitly enable or disable the socket notifier, especially for write notifiers.
Note for Windows users: The socket passed to
QSocketNotifier
will become non-blocking, even if it was created as a blocking socket.See also
- PySide2.QtCore.QSocketNotifier.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.
Constant
Description
QSocketNotifier.Read
There is data to be read.
QSocketNotifier.Write
Data can be written.
QSocketNotifier.Exception
An exception has occurred. We recommend against using this.
See also
QSocketNotifier()
type()
- PySide2.QtCore.QSocketNotifier.isEnabled()¶
- Return type:
bool
Returns
true
if the notifier is enabled; otherwise returnsfalse
.See also
- PySide2.QtCore.QSocketNotifier.setEnabled(arg__1)¶
- Parameters:
arg__1 – 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 itstype
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 emittedSee also
isEnabled()
activated()
- PySide2.QtCore.QSocketNotifier.socket()¶
- Return type:
qintptr
Returns the socket identifier specified to the constructor.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.