KPtyDevice Class

Encapsulates KPty into a QIODevice, so it can be used with Q*Stream, etc. More...

Header: #include <KPtyDevice>
CMake: find_package(KF6 REQUIRED COMPONENTS Pty)
target_link_libraries(mytarget PRIVATE KF6::Pty)
Inherits: QIODevice and KPty

Public Functions

KPtyDevice(QObject *parent = nullptr)
virtual ~KPtyDevice() override
bool isSuspended() const
bool open(int fd, QIODeviceBase::OpenMode mode = ReadWrite | Unbuffered)
void setSuspended(bool suspended)

Reimplemented Public Functions

virtual void close() override
virtual bool isSequential() const override
virtual bool open(QIODeviceBase::OpenMode mode = ReadWrite | Unbuffered) override

Signals

void readEof()

Detailed Description

Member Function Documentation

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

Constructor

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

Destructor:

If the pty is still open, it will be closed. Note, however, that an utmp registration is not undone.

[override virtual] void KPtyDevice::close()

Reimplements: QIODevice::close().

Close the pty master/slave pair.

[override virtual] bool KPtyDevice::isSequential() const

Reimplements: QIODevice::isSequential() const.

Returns always true

bool KPtyDevice::isSuspended() const

Returns true if the KPtyDevice is not monitoring the pty for incoming data.

Do not use on closed ptys.

See setSuspended()

[override virtual] bool KPtyDevice::open(QIODeviceBase::OpenMode mode = ReadWrite | Unbuffered)

Reimplements: QIODevice::open(QIODeviceBase::OpenMode mode).

Create a pty master/slave pair.

Returns true if a pty pair was successfully opened

bool KPtyDevice::open(int fd, QIODeviceBase::OpenMode mode = ReadWrite | Unbuffered)

Open using an existing pty master. The ownership of the fd remains with the caller, i.e., close() will not close the fd.

This is useful if you wish to attach a secondary "controller" to an existing pty device such as a terminal widget. Note that you will need to use setSuspended() on both devices to control which one gets the incoming data from the pty.

fd an open pty master file descriptor.

mode the device mode to open the pty with.

Returns true if a pty pair was successfully opened

[signal] void KPtyDevice::readEof()

Emitted when EOF is read from the PTY.

Data may still remain in the buffers.

void KPtyDevice::setSuspended(bool suspended)

Sets whether the KPtyDevice monitors the pty for incoming data.

When the KPtyDevice is suspended, it will no longer attempt to buffer data that becomes available from the pty and it will not emit any signals.

Do not use on closed ptys. After a call to open(), the pty is not suspended. If you need to ensure that no data is read, call this function before the main loop is entered again (i.e., immediately after opening the pty).

See also isSuspended().