#include <QApplication>
#include "telnetWindow.h"
int main(int argc, char *argv[])
{
telnetWindow client;
client.show();
return app.exec();
}
#include <QApplication>
#include "telnetWindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
telnetWindow client;
client.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
#ifndef TELNETWINDOW_H
#define TELNETWINDOW_H
//#include <QProcess>
//#include <QtGui>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QAbstractSocket>
#include "ui_telnet.h"
class telnetWindow
: public QWidget,
private Ui
::telnetWindow{
Q_OBJECT
public :
~telnetWindow();
private slots:
void read_data();
void enableButton();
private:
//QTcpSocket tcpSocket2;
// QString currentFortune;
// QString mystring;
// quint16 blockSize;
//void startConsole();
//void exitConsole();
};
#endif
#ifndef TELNETWINDOW_H
#define TELNETWINDOW_H
//#include <QProcess>
//#include <QtGui>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QAbstractSocket>
#include "ui_telnet.h"
class telnetWindow : public QWidget,private Ui::telnetWindow
{
Q_OBJECT
public :
telnetWindow(QWidget *parent = 0);
~telnetWindow();
private slots:
void read_data();
void displayError(QAbstractSocket::SocketError socketError);
void enableButton();
private:
QTcpSocket *tcpSocket;
//QTcpSocket tcpSocket2;
// QString currentFortune;
// QString mystring;
// quint16 blockSize;
//void startConsole();
//void exitConsole();
};
#endif
To copy to clipboard, switch view to plain text mode
#include <QtGui>
#include "telnetWindow.h"
//#include<iostream.h>
//use namespace std;
telnetWindow
::telnetWindow(QWidget *parent
) {
setupUi(this);
connect(lineEdit_ipAdd,
SIGNAL(textChanged
(const QString &)),
this, SLOT(enableButton()));
connect(lineEdit_portNo,
SIGNAL(textChanged
(const QString &)),
this, SLOT(enableButton()));
connect(pushButton_telnet, SIGNAL(clicked()),
this, SLOT(read_data()));
//connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(read_data()));
//textEdit->append("----------------Console Window-----------------------------");
lineEdit_portNo->setFocus();
}
telnetWindow::~telnetWindow()
{};
void telnetWindow::read_data()
{
int ret_val;
pushButton_telnet->setEnabled(true);
tcpSocket->abort();
tcpSocket->connectToHost(lineEdit_ipAdd->text(),
lineEdit_portNo
->text
().
toInt(),
QIODevice::ReadWrite);
//tcpSocket->write(data);
if(tcpSocket->waitForConnected(-1))
{
//textEdit->append("Console conncted");
//qdebug() << "Connected";
ret_val = tcpSocket->state();
// cout << ret_val;
if(tcpSocket->waitForReadyRead())
{
tcpSocket->flush();
//cout << tcpSocket->waitForReadyRead();
//while(tcpSocket->canReadLine())
// {
//QString text;
//mystring=tcpSocket->readLine();
consoleop = tcpSocket->readAll();
QString text
= textEdit
->toPlainText
()+QString::fromLocal8Bit(consoleop
);
//QString text=tcpSocket->readAll();
//textEdit->append(text);
//cout<<text;
textEdit->append(consoleop);
label->setText(text);
textEdit->insert(consoleop);
label->setText(text);
// qdebug() << text;
// }
pushButton_telnet->setEnabled(false);
}
}
}
#include <QtGui>
#include "telnetWindow.h"
//#include<iostream.h>
//use namespace std;
telnetWindow::telnetWindow(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
tcpSocket = new QTcpSocket(this);
connect(lineEdit_ipAdd, SIGNAL(textChanged(const QString &)),
this, SLOT(enableButton()));
connect(lineEdit_portNo, SIGNAL(textChanged(const QString &)),
this, SLOT(enableButton()));
connect(pushButton_telnet, SIGNAL(clicked()),
this, SLOT(read_data()));
//connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(read_data()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(displayError(QAbstractSocket::SocketError)));
//textEdit->append("----------------Console Window-----------------------------");
lineEdit_portNo->setFocus();
}
telnetWindow::~telnetWindow()
{};
void telnetWindow::read_data()
{
QByteArray consoleop;
int ret_val;
pushButton_telnet->setEnabled(true);
tcpSocket->abort();
tcpSocket->connectToHost(lineEdit_ipAdd->text(),
lineEdit_portNo->text().toInt(),QIODevice::ReadWrite);
//tcpSocket->write(data);
if(tcpSocket->waitForConnected(-1))
{
//textEdit->append("Console conncted");
//qdebug() << "Connected";
ret_val = tcpSocket->state();
// cout << ret_val;
if(tcpSocket->waitForReadyRead())
{
tcpSocket->flush();
//cout << tcpSocket->waitForReadyRead();
//while(tcpSocket->canReadLine())
// {
//QString text;
//mystring=tcpSocket->readLine();
consoleop = tcpSocket->readAll();
QString text = textEdit->toPlainText()+QString::fromLocal8Bit(consoleop);
//QString text=tcpSocket->readAll();
//textEdit->append(text);
//cout<<text;
textEdit->append(consoleop);
label->setText(text);
textEdit->insert(consoleop);
label->setText(text);
// qdebug() << text;
// }
pushButton_telnet->setEnabled(false);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks