QTcpSocketWrapper Class

A wrapper around QTcpSocket. More...

Header: #include <qtcpsocketwrappertask.h>
Inherits: QObject

Note: All functions in this class are reentrant.

Public Functions

QTcpSocketWrapper(QObject *parent = nullptr)
virtual ~QTcpSocketWrapper() override
void setAddress(const QHostAddress &address)
void setPort(quint16 port)
void setWriteData(const QByteArray &data)
QTcpSocket *socket() const
void start()

Signals

void done(QtTaskTree::DoneResult result)
void started()

Detailed Description

QTcpSocketWrapper is a convenient wrapper around QTcpSocket.

Configure the QTcpSocketWrapper with setAddress(), setPort(), and setWriteData() before calling start().

The wrapped QTcpSocket may be accessed via socket() method. The QTcpSocket is created dynamically by the start() method and managed by QTcpSocketWrapper. It is deleted just after emitting done() signal.

Member Function Documentation

QTcpSocketWrapper::QTcpSocketWrapper(QObject *parent = nullptr)

Creates QTcpSocketWrapper with a given parent.

[override virtual noexcept] QTcpSocketWrapper::~QTcpSocketWrapper()

Destroys the QTcpSocketWrapper. If the accociated socket() is still running, it's aborted.

[signal] void QTcpSocketWrapper::done(QtTaskTree::DoneResult result)

This signal is emitted after the associated QTcpSocket finished. The passed result indicates whether it has finished with success or an error.

See also socket().

void QTcpSocketWrapper::setAddress(const QHostAddress &address)

Set the address to be used on start().

void QTcpSocketWrapper::setPort(quint16 port)

Set the port to be used on start().

void QTcpSocketWrapper::setWriteData(const QByteArray &data)

Set the data to be used on start(). If not empty, the data is written automatically to the socket after the connection is established.

QTcpSocket *QTcpSocketWrapper::socket() const

Returns the pointer to the accociated QTcpSocket. Before the QTcpSocketWrapper is started and after it's finished, this function returns nullptr. It's safe to access the QTcpSocket after the started() signal is emitted and until done() signal is emitted.

void QTcpSocketWrapper::start()

Starts the QTcpSocketWrapper.

[signal] void QTcpSocketWrapper::started()

This signal is emitted after the managed QTcpSocket is connected.

See also start().

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