QTcpSocket Class

QTcpSocket 类提供了一个 TCP 套接字。更多

Header: #include <QTcpSocket>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network
继承: QAbstractSocket
继承于

QSctpSocketQSslSocket

注意:该类中的所有函数都是可重入的

公共函数

QTcpSocket(QObject *parent = nullptr)
virtual ~QTcpSocket()

详细说明

TCP(传输控制协议)是一种可靠、面向流、面向连接的传输协议。它特别适用于数据的连续传输。

QTcpSocket 是QAbstractSocket 的一个方便子类,可用于建立 TCP 连接和传输数据流。详情请查看QAbstractSocket 文档。

注意: TCP 套接字不能在QIODeviceBase::Unbuffered 模式下打开。

另请参阅 QTcpServer,QUdpSocket,QNetworkAccessManager,财富服务器财富客户端线程财富服务器阻塞财富客户端Torrent 示例

成员函数文档

[explicit] QTcpSocket::QTcpSocket(QObject *parent = nullptr)

创建一个状态为UnconnectedState 的 QTcpSocket 对象。

parent 将传递给 构造函数。QObject

另请参阅 socketType().

[virtual noexcept] QTcpSocket::~QTcpSocket()

销毁套接字,必要时关闭连接。

另请参阅 close().

© 2025 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.