Simple QTcpServer and QTcpSocket client -> failed
-
Hello everyone, I'm wondering what I'm doing wrong in this simple and easy piece of code.
There are 2 applications, a Server and a Client.
In the first application, I create a QtcpServer which is listening to localhost:12345. In this server, I have bound the newConnection signal. On the Client side, I have created a simple QTcpSocket. This client make a connection to the server and do nothing else.--
The problem is when there is an incoming connection in the server, I get a first time exception even if my function which is bind to the newConnection signal from the server is empty.Here is my code, and the error I get.
Thank you for your help.
Paolo
@
//---------------client---------------
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Client s;
return a.exec();
}Client::Client()
{
QTcpSocket* socket = new QTcpSocket();
socket->connectToHost("127.0.0.1",12345);
}Client::~Client()
{}
//-------------------Server-------------------------------------int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Server server;
server.start();return app.exec();
}Server::Server(){
QObject::connect(this, SIGNAL(newConnection()), this, SLOT(newpending()));
}void Server::start(){
listen(QHostAddress("127.0.0.1"),12345);
}
void Server::newpending(){
QTcpSocket* s = nextPendingConnection();
s->waitForConnected();
}
@And the error is localised into : qtcoreapplication.h
inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
{ if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }The log of the call stack:
QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver=0x005df0d8, QEvent * event=0x003cd8a8) Line 231 + 0x39 bytes C++
QtCored4.dll!qt_internal_proc(HWND__ * hwnd=0x00250736, unsigned int message=1024, unsigned int wp=344, long lp=8) Line 488 + 0xf bytes C++
user32.dll!_InternalCallWinProc@20() + 0x23 bytes
user32.dll!_UserCallWinProcCheckWow@32() + 0xb7 bytes
user32.dll!_DispatchMessageWorker@8() + 0xed bytes
user32.dll!_DispatchMessageW@4() + 0xf bytes
QtCored4.dll!QEventDispatcherWin32::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 814 C++
QtGuid4.dll!QGuiEventDispatcherWin32::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 1212 + 0x15 bytes C++
QtCored4.dll!QEventLoop::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 150 C++
QtCored4.dll!QEventLoop::exec(QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 204 + 0x2d bytes C++
QtCored4.dll!QCoreApplication::exec() Line 1221 + 0x15 bytes C++
QtGuid4.dll!QApplication::exec() Line 3824 C++
QTServer.exe!main(int argc=1, char * * argv=0x005d6530) Line 52 + 0x6 bytes C++
QTServer.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
QTServer.exe!mainCRTStartup() Line 371 C
kernel32.dll!764933aa()
ntdll.dll!___RtlUserThreadStart@8() + 0x27 bytes
ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes
First-chance exception at 0x7620c41f in QTServer.exe: Microsoft C++ exception: int at memory location 0x003cd2b0..
Thank you for your help