内容表

上一话题

QSocketDescriptor

下一话题

QSortFilterProxyModel

QSocketNotifier

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

Inheritance diagram of PySide2.QtCore.QSocketNotifier

概要

函数

详细描述

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.

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.

最后,可以使用 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.

class QSocketNotifier ( arg__1 , arg__2 [ , parent=None ] )

QSocketNotifier(socket, arg__2[, parent=None])

param parent

QObject

param arg__1

PyObject

param socket

qintptr

param arg__2

Type

Constructs a socket notifier with the given parent . It enables the socket , and watches for events of the given type .

It is generally advisable to explicitly enable or disable the socket notifier, especially for write notifiers.

Windows 用户注意: The socket passed to QSocketNotifier will become non-blocking, even if it was created as a blocking socket.

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.

常量

描述

QSocketNotifier.Read

有数据要读取。

QSocketNotifier.Write

数据可以被写入。

QSocketNotifier.Exception

发生异常。建议不要使用此。

另请参阅

QSocketNotifier() type()

PySide2.QtCore.QSocketNotifier. isEnabled ( )
返回类型

bool

返回 true 若通知被启用;否则返回 false .

另请参阅

setEnabled()

PySide2.QtCore.QSocketNotifier. setEnabled ( arg__1 )
参数

arg__1 bool

enable 为 true,通知被启用;否则通知被禁用。

通知默认是启用的,即,它发射 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

另请参阅

isEnabled() activated()

PySide2.QtCore.QSocketNotifier. socket ( )
返回类型

qintptr

Returns the socket identifier specified to the constructor.

另请参阅

type()

PySide2.QtCore.QSocketNotifier. type ( )
返回类型

Type

Returns the socket event type specified to the constructor.

另请参阅

socket()