I have watched VoidRealm's Youtube video, C++ Qt 67 - QTCPServer - a basic TCP server application
and followed his instructions, however, I can't connect to the QTcpServer I created using Telnet.
My Code:
//myserver.h
#ifndef MYSERVER_H
#define MYSERVER_H
#include <QObject>
#include <QDebug>
#include <QTcpServer>
#include <QTcpSocket>
class MyServer : public QObject
{
Q_OBJECT
public:
explicit MyServer(QObject *parent = nullptr);
void newConnection();
signals:
private:
QTcpServer *server;
};
#endif // MYSERVER_H
//myserver.cpp
#include "myserver.h"
MyServer::MyServer(QObject *parent)
: QObject{parent}
{
server = new QTcpServer(this);
connect(server,SIGNAL(newConnection()),this,SLOT(newConnection()));
if(!server->listen(QHostAddress::Any, 1234))
{
qDebug() << "Server could not start!";
}else{
qDebug() << "Server started!";
}
}
void MyServer::newConnection()
{
QTcpSocket *socket = server->nextPendingConnection();
socket->write("hello client\r\n");
socket->flush();
socket->waitForBytesWritten(3000);
socket->close();
}
Running this code, in the Console screen I get
qt.core.qobject.connect: QObject::connect: No such slot MyServer::newConnection() in ..\First_Server\myserver.cpp:8
Server started!
but when I open a command prompt and do the following steps:
...>telnet
Welcome to Microsoft Telnet Client
Escape Character is 'CTRL+]'
Microsoft Telnet> open 127.0.0.1 1234
Connecting To 127.0.0.1...
It is not connecting. Can anyone tell me what I have done wrong? I am using Qt 6.3.0.