source: ogBrowser-Git/qtermwidget/examples/cpp/RemoteTerm/remoteterm.cpp @ c0cec9d

jenkinsmain
Last change on this file since c0cec9d was 64efc22, checked in by Vadim Troshchinskiy <vtroshchinskiy@…>, 20 months ago

Update qtermwidget to modern version

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