Hello,

I am trying to establish a telnet connection in a console application. I have the following code:

Qt Code:
  1. QTcpSocket *QTcpSocketMine = new QTcpSocket();
  2. QTcpSocketMine->connectToHost("192.168.1.1", 23);
  3. if (QTcpSocketMine->isOpen())
  4. {
  5. qDebug() << "QTcpSocketMine->isOpen() == true";
  6. } else
  7. {
  8. qDebug() << "QTcpSocketMine->isOpen() == false";
  9. }
  10.  
  11. if (QTcpSocketMine->isValid())
  12. {
  13. qDebug() << "QTcpSocketMine->isValid() == true";
  14. } else
  15. {
  16. qDebug() << "QTcpSocketMine->isValid() == false";
  17. }
  18.  
  19. if (QTcpSocketMine->waitForConnected(3000))
  20. {
  21. qDebug() << "connection established.";
  22. } else
  23. {
  24. QString QStringErrorString = QTcpSocketMine->errorString();
  25. qDebug() << QStringErrorString;
  26. }
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:

Qt Code:
  1. #ifndef QMYPROCESS_H
  2. #include <QProcess>
  3. #include <QDebug>
  4. #include <QTcpSocket>
  5.  
  6. class QMyProcess: public QProcess
  7. {
  8. Q_OBJECT;
  9.  
  10. public:
  11. QMyProcess();
  12.  
  13. public slots:
  14. void connectionComplete();
  15. void errorOccured(QAbstractSocket::SocketError socketError);
  16. void hostFoundComplete();
  17. void handleStateChanged(QAbstractSocket::SocketState socketState);
  18. };
  19.  
  20. #endif // QMYPROCESS_H
To copy to clipboard, switch view to plain text mode 
Do I miss something?