近日要用Qt设计路灯节能监控系统的上位机,用到QTcpSocket类,参考文档英文的,看起来不方便,按学习笔记的方式,归纳如下:
1. enum QAbstractSocket::NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
Constant | Value | Description |
---|---|---|
QAbstractSocket::IPv4Protocol | 0 | IPv4 |
QAbstractSocket::IPv6Protocol | 1 | IPv6 |
QAbstractSocket::UnknownNetworkLayerProtocol | -1 | Other than IPv4 and IPv6 |
2.enum QIODevice::OpenModeFlag
flags QIODevice::OpenMode
This enum is used with open() to describe the mode in which a device is opened. It is also returned by openMode().
Constant | Value | Description |
---|---|---|
QIODevice::NotOpen | 0x0000 | The device is not open. |
QIODevice::ReadOnly | 0x0001 | The device is open for reading. |
QIODevice::WriteOnly | 0x0002 | The device is open for writing. |
QIODevice::ReadWrite | ReadOnly | WriteOnly | The device is open for reading and writing. |
QIODevice::Append | 0x0004 | The device is opened in append mode, so that all data is written to the end of the file. |
QIODevice::Truncate | 0x0008 | If possible, the device is truncated before it is opened. All earlier contents of the device are lost. |
QIODevice::Text | 0x0010 | When reading, the end-of-line terminators are translated to '\n'. When writing, the end-of-line terminators are translated to the local encoding, for example '\r\n' for Win32. |
QIODevice::Unbuffered | 0x0020 | Any buffer in the device is bypassed. |
列出了打开设备的状态。如设备未打开,以只读的方式打开,以写的方式打开。
3.enum QAbstractSocket::SocketError
This enum describes the socket errors that can occur.
Constant | Value | Description |
---|---|---|
QAbstractSocket::ConnectionRefusedError | 0 | The connection was refused by the peer (or timed out). |
QAbstractSocket::RemoteHostClosedError | 1 | The remote host closed the connection. Note that the client socket (i.e., this socket) will be closed after the remote close notification has been sent. |
QAbstractSocket::HostNotFoundError | 2 | The host address was not found. |
QAbstractSocket::SocketAccessError | 3 | The socket operation failed because the application lacked the required privileges. |
QAbstractSocket::SocketResourceError | 4 | The local system ran out of resources (e.g., too many sockets). |
QAbstractSocket::SocketTimeoutError | 5 | The socket operation timed out. |
QAbstractSocket::DatagramTooLargeError | 6 | The datagram was larger than the operating system's limit (which can be as low as 8192 bytes). |
QAbstractSocket::NetworkError | 7 | An error occurred with the network (e.g., the network cable was accidentally plugged out). |
QAbstractSocket::AddressInUseError | 8 | The address specified to QUdpSocket::bind() is already in use and was set to be exclusive. |
QAbstractSocket::SocketAddressNotAvailableError | 9 | The address specified to QUdpSocket::bind() does not belong to the host. |
QAbstractSocket::UnsupportedSocketOperationError | 10 | The requested socket operation is not supported by the local operating system (e.g., lack of IPv6 support). |
QAbstractSocket::ProxyAuthenticationRequiredError | 12 | The socket is using a proxy, and the proxy requires authentication. |
QAbstractSocket::SslHandshakeFailedError | 13 | The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket) |
QAbstractSocket::UnfinishedSocketOperationError | 11 | Used by QAbstractSocketEngine only, The last operation attempted has not finished yet (still in progress in the background). |
QAbstractSocket::ProxyConnectionRefusedError | 14 | Could not contact the proxy server because the connection to that server was denied |
QAbstractSocket::ProxyConnectionClosedError | 15 | The connection to the proxy server was closed unexpectedly (before the connection to the final peer was established) |
QAbstractSocket::ProxyConnectionTimeoutError | 16 | The connection to the proxy server timed out or the proxy server stopped responding in the authentication phase. |
QAbstractSocket::ProxyNotFoundError | 17 | The proxy address set with setProxy() (or the application proxy) was not found. |
QAbstractSocket::ProxyProtocolError | 18 | The connection negotiation with the proxy server because the response from the proxy server could not be understood. |
QAbstractSocket::UnknownSocketError | -1 | An unidentified error occurred. |
列出了连接中可能发 生的错误,错误一一列在上表中。
4.enum QAbstractSocket::SocketState
This enum describes the different states in which a socket can be.
Constant | Value | Description |
---|---|---|
QAbstractSocket::UnconnectedState | 0 | The socket is not connected. |
QAbstractSocket::HostLookupState | 1 | The socket is performing a host name lookup. |
QAbstractSocket::ConnectingState | 2 | The socket has started establishing a connection. |
QAbstractSocket::ConnectedState | 3 | A connection is established. |
QAbstractSocket::BoundState | 4 | The socket is bound to an address and port (for servers). |
QAbstractSocket::ClosingState | 6 | The socket is about to close (data may still be waiting to be written). |
QAbstractSocket::ListeningState | 5 | For internal use only. |
列出了套接字的连接状态
5.enum QAbstractSocket::SocketType
This enum describes the transport layer protocol.
Constant | Value | Description |
---|---|---|
QAbstractSocket::TcpSocket | 0 | TCP |
QAbstractSocket::UdpSocket | 1 | UDP |
QAbstractSocket::UnknownSocketType | -1 | Other than TCP and UDP |
See also QAbstractSocket::socketType().
列出了套接字的连接方式。
表里面的内容以后有空整理,谢谢!
转载于:https://blog.51cto.com/qtlinux/574431