本页内容

QTcpSocket Class

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

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

QSctpSocket 以及QSslSocket

注意:该类中的所有函数均为可重入的。

公共函数

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

详细说明

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

QTcpSocket 是QAbstractSocket 的一个便捷子类,允许您建立 TCP 连接并传输数据流。有关详细信息,请参阅QAbstractSocket 文档。

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

另请参阅 QTcpServer 、QUdpSocket 、QNetworkAccessManager 、Fortune 服务器、Fortune 客户端、多线程 Fortune 服务器、阻塞式 Fortune 客户端以及Torrent 示例。

成员函数文档

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

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

parent 该参数将传递给QObject 构造函数。

另请参阅 socketType()。

[virtual noexcept] QTcpSocket::~QTcpSocket()

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

另请参阅 close()。

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