Hello,
I am trying to establish a telnet connection in a console application. I have the following code:
QTcpSocketMine->connectToHost("192.168.1.1", 23);
if (QTcpSocketMine->isOpen())
{
qDebug() << "QTcpSocketMine->isOpen() == true";
} else
{
qDebug() << "QTcpSocketMine->isOpen() == false";
}
if (QTcpSocketMine->isValid())
{
qDebug() << "QTcpSocketMine->isValid() == true";
} else
{
qDebug() << "QTcpSocketMine->isValid() == false";
}
if (QTcpSocketMine->waitForConnected(3000))
{
qDebug() << "connection established.";
} else
{
QString QStringErrorString
= QTcpSocketMine
->errorString
();
qDebug() << QStringErrorString;
}
QTcpSocket *QTcpSocketMine = new QTcpSocket();
QTcpSocketMine->connectToHost("192.168.1.1", 23);
if (QTcpSocketMine->isOpen())
{
qDebug() << "QTcpSocketMine->isOpen() == true";
} else
{
qDebug() << "QTcpSocketMine->isOpen() == false";
}
if (QTcpSocketMine->isValid())
{
qDebug() << "QTcpSocketMine->isValid() == true";
} else
{
qDebug() << "QTcpSocketMine->isValid() == false";
}
if (QTcpSocketMine->waitForConnected(3000))
{
qDebug() << "connection established.";
} else
{
QString QStringErrorString = QTcpSocketMine->errorString();
qDebug() << QStringErrorString;
}
To copy to clipboard, switch view to plain text mode
If I set the parameter of QTcpSocketMine->waitForConnected to -1 the program does not exit any more. If i read the error message with
QString QStringErrorString = QTcpSocketMine->errorString();
qDebug() << QStringErrorString;
it prints Socket operation timed out. If I open putty and connect to 192.168.1.1:23 it immediately works. Same with the Windows telnet client. What could that be?
Another problem is, that the signals and slots do not work.
I define
connect(QTcpSocketMine, SIGNAL(connected()), this, SLOT(connectionComplete()));
connect(QTcpSocketMine, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorOccured(QAbstractSocket::SocketError)));
connect(QTcpSocketMine, SIGNAL(hostFound()), this, SLOT(hostFoundComplete()));
connect(QTcpSocketMine, SIGNAL(stateChanged(QAbstractSocket::SocketState)) , this, SLOT(handleStateChanged(QAbstractSocket::SocketSta te)));
in the cpp and my whole h looks like that:
#ifndef QMYPROCESS_H
#include <QProcess>
#include <QDebug>
#include <QTcpSocket>
{
Q_OBJECT;
public:
QMyProcess();
public slots:
void connectionComplete();
void hostFoundComplete();
};
#endif // QMYPROCESS_H
#ifndef QMYPROCESS_H
#include <QProcess>
#include <QDebug>
#include <QTcpSocket>
class QMyProcess: public QProcess
{
Q_OBJECT;
public:
QMyProcess();
public slots:
void connectionComplete();
void errorOccured(QAbstractSocket::SocketError socketError);
void hostFoundComplete();
void handleStateChanged(QAbstractSocket::SocketState socketState);
};
#endif // QMYPROCESS_H
To copy to clipboard, switch view to plain text mode
Do I miss something?
Bookmarks