QtTaskTree::QTcpSocketWrapper Class | Qt TaskTree | Qt 6.11.1
Description: A wrapper around QTcpSocket.

- Qt 6.11
- Qt TaskTree
- C++ Classes
- QTcpSocketWrapper
- Qt 6.11.1 Reference Documentation

# QtTaskTree::QTcpSocketWrapper Class

class QtTaskTree::QTcpSocketWrapper

A wrapper around QTcpSocket. More...

Header: | `#include <qtcpsocketwrappertask.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS TaskTree)` `target_link_libraries(mytarget PRIVATE Qt6::TaskTree)`
qmake: | `QT += tasktree`
Since: | Qt 6.11
Inherits: | QObject

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

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

## Signals

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

## Reimplemented Protected Functions

virtual bool | event(QEvent *event) override

## Detailed Description

QTcpSocketWrapper is a convenient wrapper around QTcpSocket.

Configure the QTcpSocketWrapper with setAddress(), setPort(), and setData() 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

### `[explicit]` QTcpSocketWrapper::QTcpSocketWrapper(QObject *parent)

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().

### `[override virtual protected]` bool QTcpSocketWrapper::event(QEvent *event)

Reimplements: QObject::event(QEvent *e).

### void QTcpSocketWrapper::setAddress(const QHostAddress &address)

Set the address to be used on start().

### void QTcpSocketWrapper::setData(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.

### void QTcpSocketWrapper::setPort(quint16 port)

Set the port to be used on start().

### 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().