<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Simple QTcpServer and QTcpSocket client -&gt; failed]]></title><description><![CDATA[<p dir="auto">Hello everyone, I'm wondering what I'm doing wrong in this simple and easy piece of code.<br />
There are 2 applications, a Server and a Client.<br />
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.--<br />
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.</p>
<p dir="auto">Here is my code, and the error I get.</p>
<p dir="auto">Thank you for your help.</p>
<p dir="auto">Paolo</p>
<p dir="auto">@<br />
//---------------client---------------<br />
int main(int argc, char *argv[])<br />
{<br />
QApplication a(argc, argv);<br />
Client s;<br />
return a.exec();<br />
}</p>
<p dir="auto">Client::Client()<br />
{<br />
QTcpSocket* socket = new QTcpSocket();<br />
socket-&gt;connectToHost("127.0.0.1",12345);<br />
}</p>
<p dir="auto">Client::~Client()<br />
{</p>
<p dir="auto">}<br />
//-------------------Server-------------------------------------</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
Server server;<br />
server.start();</p>
<p dir="auto">return app.exec();<br />
}</p>
<p dir="auto">Server::Server(){<br />
QObject::connect(this, SIGNAL(newConnection()), this, SLOT(newpending()));<br />
}</p>
<p dir="auto">void Server::start(){<br />
listen(QHostAddress("127.0.0.1"),12345);<br />
}<br />
void Server::newpending(){<br />
QTcpSocket* s = nextPendingConnection();<br />
s-&gt;waitForConnected();<br />
}<br />
@</p>
<p dir="auto">And the error is localised into : qtcoreapplication.h</p>
<p dir="auto">inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)<br />
{  if (event) event-&gt;spont = false; return self ? self-&gt;notifyInternal(receiver, event) : false; }</p>
<p dir="auto">The log of the call stack:</p>
<blockquote>
<p dir="auto">QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver=0x005df0d8, QEvent * event=0x003cd8a8)  Line 231 + 0x39 bytes C++</p>
</blockquote>
<p dir="auto">QtCored4.dll!qt_internal_proc(HWND__ * hwnd=0x00250736, unsigned int message=1024, unsigned int wp=344, long lp=8)  Line 488 + 0xf bytes C++</p>
<p dir="auto">user32.dll!_InternalCallWinProc@20()  + 0x23 bytes</p>
<p dir="auto">user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes</p>
<p dir="auto">user32.dll!_DispatchMessageWorker@8()  + 0xed bytes</p>
<p dir="auto">user32.dll!_DispatchMessageW@4()  + 0xf bytes</p>
<p dir="auto">QtCored4.dll!QEventDispatcherWin32::processEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 814 C++</p>
<p dir="auto">QtGuid4.dll!QGuiEventDispatcherWin32::processEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 1212 + 0x15 bytes C++</p>
<p dir="auto">QtCored4.dll!QEventLoop::processEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 150 C++</p>
<p dir="auto">QtCored4.dll!QEventLoop::exec(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 204 + 0x2d bytes C++</p>
<p dir="auto">QtCored4.dll!QCoreApplication::exec()  Line 1221 + 0x15 bytes C++</p>
<p dir="auto">QtGuid4.dll!QApplication::exec()  Line 3824 C++</p>
<p dir="auto">QTServer.exe!main(int argc=1, char * * argv=0x005d6530)  Line 52 + 0x6 bytes C++</p>
<p dir="auto">QTServer.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes C</p>
<p dir="auto">QTServer.exe!mainCRTStartup()  Line 371 C</p>
<p dir="auto">kernel32.dll!764933aa()</p>
<p dir="auto">ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes</p>
<p dir="auto">ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes</p>
<p dir="auto">First-chance exception at 0x7620c41f in QTServer.exe: Microsoft C++ exception: int at memory location 0x003cd2b0..</p>
<p dir="auto">Thank you for your help</p>
]]></description><link>https://forum.qt.io/topic/29622/simple-qtcpserver-and-qtcpsocket-client-failed</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 01:22:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/29622.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 19 Jul 2013 09:47:43 GMT</pubDate><ttl>60</ttl></channel></rss>