The QSocketNotifier class provides support for monitoring activity on a file descriptor. 更多...
| 頭: | #include <QSocketNotifier> |
| qmake: | QT += core |
| 繼承: | QObject |
| enum | Type { Read, Write, Exception } |
| QSocketNotifier (qintptr socket , Type type , QObject * parent = Q_NULLPTR) | |
| ~QSocketNotifier () | |
| bool | isEnabled () const |
| qintptr | socket () const |
| 類型 | type () const |
| void | setEnabled (bool enable ) |
| void | activated (int socket ) |
| virtual bool | event (QEvent * e ) |
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 ( QCoreApplication::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 ( 讀取 , 寫入 , 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 () 函數以確定通知的當前狀態。
最後,可以使用 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.
另請參閱 QFile , QProcess , QTcpSocket ,和 QUdpSocket .
此枚舉描述套接字通知程序可以識彆的各種類型的事件。必須指定類型當構造套接字通知程序時。
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
|
0
|
有數據要讀取。 |
QSocketNotifier::Write
|
1
|
數據可以被寫入。 |
QSocketNotifier::Exception
|
2
|
發生異常。建議不要使用此。 |
另請參閱 QSocketNotifier () 和 type ().
構造套接字通知程序采用給定 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.
另請參閱 setEnabled () 和 isEnabled ().
銷毀此套接字通知程序。
[signal]
void
QSocketNotifier::
activated
(
int
socket
)
此信號被發射每當套接字通知程序被啓用時,且套接字事件對應 type 齣現。
套接字標識符被傳入 socket 參數。
注意: 這是私有信號。它可以用於信號連接,但不能由用戶發射。
[virtual protected]
bool
QSocketNotifier::
event
(
QEvent
*
e
)
重實現自 QObject::event ().
返迴
true
若通知被啓用;否則返迴
false
.
另請參閱 setEnabled ().
[slot]
void
QSocketNotifier::
setEnabled
(
bool
enable
)
若 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 ().
Returns the socket identifier specified to the constructor.
另請參閱 type ().
Returns the socket event type specified to the constructor.
另請參閱 socket ().