<?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[connect signal to slot crazy problem]]></title><description><![CDATA[<p dir="auto">this is my main.cpp</p>
<pre><code>#include &lt;QGuiApplication&gt;
#include &lt;QQmlApplicationEngine&gt;
#include &lt;QTcpSocket&gt;
#include &lt;QTcpServer&gt;
#include "handler.h"

handler *h = new handler();
int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    return app.exec();
}

</code></pre>
<p dir="auto">this is my handler.h</p>
<pre><code>#ifndef HANDLER_H
#define HANDLER_H

#include &lt;QObject&gt;
#include &lt;QTcpServer&gt;
#include &lt;QTcpSocket&gt;
class handler : public QObject
{
    Q_OBJECT
public:
    explicit handler(QObject *parent = 0);

signals:
 void mysignal();
public slots:
    void newConnection();
private:
    QTcpServer *mserver;
    QTcpSocket* socket;
};

#endif // HANDLER_H

</code></pre>
<p dir="auto">this is my handler.cpp</p>
<pre><code>#include "handler.h"

handler::handler(QObject *parent) : QObject(parent)
{
    mserver =  new QTcpServer();
    connect(
         mserver, &amp;QTcpServer::newConnection,
         this , &amp;handler::newConnection
    );
    if(!mserver-&gt;listen(QHostAddress::Any, 1234)){
            qDebug() &lt;&lt; "connection failed";
    }else{
            qDebug() &lt;&lt; "connection success!!";
    }

}


void handler::newConnection(){
    qDebug() &lt;&lt; "connection Accepted";
    QTcpSocket* socket = mserver-&gt;nextPendingConnection();
    socket-&gt;write("HELLO WORLD!\r\n");
    socket-&gt;waitForBytesWritten(300);
    socket-&gt;close();
}
</code></pre>
<p dir="auto">this code should should should be work but does not work why?<br />
newConnection slot does not fire</p>
]]></description><link>https://forum.qt.io/topic/84010/connect-signal-to-slot-crazy-problem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 06:45:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/84010.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 Oct 2017 08:23:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to connect signal to slot crazy problem on Mon, 09 Oct 2017 08:38:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fireghostea">@<bdi>fireghostea</bdi></a> Where exactly did you put this line now? It must be after QGuiApplication app(argc, argv);</p>
]]></description><link>https://forum.qt.io/post/419558</link><guid isPermaLink="true">https://forum.qt.io/post/419558</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 09 Oct 2017 08:38:20 GMT</pubDate></item><item><title><![CDATA[Reply to connect signal to slot crazy problem on Mon, 09 Oct 2017 09:43:03 GMT]]></title><description><![CDATA[<p dir="auto">HI <a class="plugin-mentions-user plugin-mentions-a" href="/user/fireghostea">@<bdi>fireghostea</bdi></a></p>
<p dir="auto">Before initializing any Qt object,  "QApplication app(argc, argv);" should be initialized. Because it initializes all the QObject , Meta object related objects.<br />
Without initializing QApplication if signal &amp; slots connected, there is no use.</p>
<p dir="auto">The same case with your case , where  " handler *h = new handler(); " is initialized before QApplication.</p>
]]></description><link>https://forum.qt.io/post/419587</link><guid isPermaLink="true">https://forum.qt.io/post/419587</guid><dc:creator><![CDATA[yuvaram]]></dc:creator><pubDate>Mon, 09 Oct 2017 09:43:03 GMT</pubDate></item><item><title><![CDATA[Reply to connect signal to slot crazy problem on Mon, 09 Oct 2017 08:44:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> yeeeeees you solve it tnx</p>
]]></description><link>https://forum.qt.io/post/419561</link><guid isPermaLink="true">https://forum.qt.io/post/419561</guid><dc:creator><![CDATA[fireghostea]]></dc:creator><pubDate>Mon, 09 Oct 2017 08:44:04 GMT</pubDate></item><item><title><![CDATA[Reply to connect signal to slot crazy problem on Mon, 09 Oct 2017 08:38:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fireghostea">@<bdi>fireghostea</bdi></a> Where exactly did you put this line now? It must be after QGuiApplication app(argc, argv);</p>
]]></description><link>https://forum.qt.io/post/419558</link><guid isPermaLink="true">https://forum.qt.io/post/419558</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 09 Oct 2017 08:38:20 GMT</pubDate></item><item><title><![CDATA[Reply to connect signal to slot crazy problem on Mon, 09 Oct 2017 08:37:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asperamanca">@<bdi>Asperamanca</bdi></a> i  change the position to in the main function and the problem does not solve</p>
]]></description><link>https://forum.qt.io/post/419556</link><guid isPermaLink="true">https://forum.qt.io/post/419556</guid><dc:creator><![CDATA[fireghostea]]></dc:creator><pubDate>Mon, 09 Oct 2017 08:37:15 GMT</pubDate></item><item><title><![CDATA[Reply to connect signal to slot crazy problem on Mon, 09 Oct 2017 08:34:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fireghostea">@<bdi>fireghostea</bdi></a> said in <a href="/post/419548">connect signal to slot crazy problem</a>:</p>
<blockquote>
<p dir="auto">handler *h = new handler();</p>
</blockquote>
<p dir="auto">The position of this code line outside of any method does not make much sense to me.</p>
]]></description><link>https://forum.qt.io/post/419555</link><guid isPermaLink="true">https://forum.qt.io/post/419555</guid><dc:creator><![CDATA[Asperamanca]]></dc:creator><pubDate>Mon, 09 Oct 2017 08:34:48 GMT</pubDate></item></channel></rss>