1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include "remoteterm.h"
#include <QTcpSocket>
#include <QDebug>
#include <unistd.h>
RemoteTerm::RemoteTerm(const QString &ipaddr, quint16 port, QWidget *parent)
: QTermWidget(0,parent)
{
socket = new QTcpSocket(this);
// Write what we input to remote terminal via socket
connect(this, &RemoteTerm::sendData,[this](const char *data, int size){
this->socket->write(data, size);
});
// Read anything from remote terminal via socket and show it on widget.
connect(socket,&QTcpSocket::readyRead,[this](){
QByteArray data = socket->readAll();
write(this->getPtySlaveFd(), data.data(), data.size());
});
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(atError()));
// Here we start an empty pty.
this->startTerminalTeletype();
socket->connectToHost(ipaddr, port);
}
void RemoteTerm::atError()
{
qDebug() << socket->errorString();
}
|