KPty 5.109.0
Signals | Public Member Functions | Protected Member Functions | List of all members
KPtyDevice

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

#include <kptydevice.h>

Signals

void readEof ()
 Emitted when EOF is read from the PTY.
 

Public Member Functions

 KPtyDevice (QObject *parent=nullptr)
 Constructor.
 
 ~KPtyDevice () override
 Destructor:
 
bool atEnd () const override
 
qint64 bytesAvailable () const override
 
qint64 bytesToWrite () const override
 
bool canReadLine () const override
 
void close () override
 Close the pty master/slave pair.
 
bool isSequential () const override
 
bool isSuspended () const
 Returns true if the KPtyDevice is not monitoring the pty for incoming data.
 
bool open (int fd, OpenMode mode=ReadWrite|Unbuffered)
 Open using an existing pty master.
 
bool open (OpenMode mode=ReadWrite|Unbuffered) override
 Create a pty master/slave pair.
 
void setSuspended (bool suspended)
 Sets whether the KPtyDevice monitors the pty for incoming data.
 
bool waitForBytesWritten (int msecs=-1) override
 
bool waitForReadyRead (int msecs=-1) override
 
- Public Member Functions inherited from KPty
 KPty ()
 Constructor.
 
 KPty (const KPty &)=delete
 
 ~KPty ()
 Destructor:
 
void close ()
 Close the pty master/slave pair.
 
void closeSlave ()
 Close the pty slave descriptor.
 
void login (const char *user=nullptr, const char *remotehost=nullptr)
 Creates an utmp entry for the tty.
 
void logout ()
 Removes the utmp entry for this tty.
 
int masterFd () const
 
bool open ()
 Create a pty master/slave pair.
 
bool open (int fd)
 Open using an existing pty master.
 
bool openSlave ()
 Open the pty slave descriptor.
 
KPtyoperator= (const KPty &)=delete
 
void setCTty ()
 Creates a new session and process group and makes this pty the controlling tty.
 
void setCTtyEnabled (bool enable)
 Whether this will be a controlling terminal.
 
bool setEcho (bool echo)
 Set whether the pty should echo input.
 
bool setWinSize (int lines, int columns)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Change the logical (screen) size of the pty.
 
bool setWinSize (int lines, int columns, int height, int width)
 Change the logical (screen) size of the pty.
 
int slaveFd () const
 
bool tcGetAttr (struct ::termios *ttmode) const
 Wrapper around tcgetattr(3).
 
bool tcSetAttr (struct ::termios *ttmode)
 Wrapper around tcsetattr(3) with mode TCSANOW.
 
const char * ttyName () const
 

Protected Member Functions

qint64 readData (char *data, qint64 maxSize) override
 
qint64 readLineData (char *data, qint64 maxSize) override
 
qint64 writeData (const char *data, qint64 maxSize) override
 
- Protected Member Functions inherited from KPty
 __attribute__ ((visibility("hidden"))) explicit KPty(KPtyPrivate *d)
 

Additional Inherited Members

- Protected Attributes inherited from KPty
std::unique_ptr< KPtyPrivate > const d_ptr
 

Detailed Description

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

Constructor & Destructor Documentation

◆ KPtyDevice()

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

Constructor.

◆ ~KPtyDevice()

KPtyDevice::~KPtyDevice ( )
override

Destructor:

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

Member Function Documentation

◆ atEnd()

bool KPtyDevice::atEnd ( ) const
override
Reimplemented from superclass.

◆ bytesAvailable()

qint64 KPtyDevice::bytesAvailable ( ) const
override
Reimplemented from superclass.

◆ bytesToWrite()

qint64 KPtyDevice::bytesToWrite ( ) const
override
Reimplemented from superclass.

◆ canReadLine()

bool KPtyDevice::canReadLine ( ) const
override
Reimplemented from superclass.

◆ close()

void KPtyDevice::close ( )
override

Close the pty master/slave pair.

◆ isSequential()

bool KPtyDevice::isSequential ( ) const
override
Returns
always true

◆ isSuspended()

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

◆ open() [1/2]

bool KPtyDevice::open ( int  fd,
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.

Parameters
fdan open pty master file descriptor.
modethe device mode to open the pty with.
Returns
true if a pty pair was successfully opened

◆ open() [2/2]

bool KPtyDevice::open ( OpenMode  mode = ReadWrite|Unbuffered)
override

Create a pty master/slave pair.

Returns
true if a pty pair was successfully opened

◆ readEof

void KPtyDevice::readEof ( )
signal

Emitted when EOF is read from the PTY.

Data may still remain in the buffers.

◆ setSuspended()

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