<?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[QNetworkAccessManager object not receiving the response when closing application]]></title><description><![CDATA[<p dir="auto">Hi Qt Community, I have a desktop application written in qt and a server application thats written in .Net core. I'm trying to make an api call when I'm closing my application. Server is getting my call, processing it and sending back the response but my QNetworkAccessManager object is not emitting the finished signal. Other api call that are made when using the application are working fine, Only when user click the X button to close the app at that time whatever api calls i make are not getting the response. I have checked all the ports and signal slots are in connected state and server is sending me the response. Below is the portion of the code that shows the flow.</p>
<p dir="auto">App.h</p>
<pre><code>enum class  RESPONSE_STATE {
 
        RESPONSE_RECEIVED_STATE = 0,
        RESPONSE_REQUESTED_STATE,
        RESPONSE_INVALID   

}

class CApp : public QtSingleApplication
{
    Q_OBJECT
    private: 
              //member variables
              RESPONSE_STATE m_eApiCallResponseState;
              QNetworkAccessManager* m_pNetworkManager;

    public:
              CApp( );
              ~CApp();

    public slots:
              void OnClosing();
              void OnResponseReceived(QNetworkReply* pReply);     
};
</code></pre>
<p dir="auto">App.cpp</p>
<pre><code>CApp::CApp ()
              : m_eApiCallResponseState(RESPONSE_STATE ::RESPONSE_INVALID)
              ,  m_pNetworkManager(new QNetworkAccessManager(this)
{
   m_pNetworkManager-&gt;setProxy(QNetworkProxy::NoProxy);
   connect(m_pNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(OnResponseReceived(QNetworkReply*)));
   connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onClosing()));
}

CApp::~CApp()
{
   // Disconnect all the signal slot connection
   // Close all the ports
   // Delete member variables
}

void CApp::onClosing()
{
    m_eApiCallResponseState = RESPONSE_REQUESTED_STATE;
    //I'm making api call here using m_pNetworkManager
    do
    {
    // Checked port is still connected
    }
    while(m_eApiCallResponseState  != RESPONSE_REQUESTED_STATE);
}

void CApp::OnResponseReceived(QNetworkReply* pReply)
{
   //Handle the response
  m_eApiCallResponseState  = RESPONSE_RECEIVED_STATE ;
}
</code></pre>
<p dir="auto">I have made the same api call from other place im getting the response. On making the call from the onClosing(). <code>m_pNetworkManager</code> is not emitting the<code> finished()</code> signal. introduced do while loop just to make sure response is coming or not. Any help is much appreciated.</p>
]]></description><link>https://forum.qt.io/topic/138135/qnetworkaccessmanager-object-not-receiving-the-response-when-closing-application</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 04:09:50 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138135.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Jul 2022 06:08:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 06:21:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhivarma">@<bdi>AbhiVarma</bdi></a> You should override closeEvent like shown in <a href="https://stackoverflow.com/questions/17480984/qt-how-do-i-handle-the-event-of-the-user-pressing-the-x-close-button" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/17480984/qt-how-do-i-handle-the-event-of-the-user-pressing-the-x-close-button</a> and delay the closing. Else your app is closed before it gets the response.</p>
]]></description><link>https://forum.qt.io/post/722506</link><guid isPermaLink="true">https://forum.qt.io/post/722506</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 25 Jul 2022 06:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 01 Aug 2022 06:55:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhivarma">@<bdi>AbhiVarma</bdi></a> I already explained you how you should do it without any dirty workarounds like local event loop...</p>
]]></description><link>https://forum.qt.io/post/723423</link><guid isPermaLink="true">https://forum.qt.io/post/723423</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 01 Aug 2022 06:55:44 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 01 Aug 2022 06:50:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I am handling it in the closeEvent. I'm waiting in the closeEvent until i get my response. using the following loopk. only once i get response and exiting the loop and accepting the event</p>
<p dir="auto">do<br />
{<br />
qAppObject-&gt;processEvents(QEventLoop::WaitForMoreEvents, 500);<br />
}<br />
while(m_eApiCallResponseState  != RESPONSE_REQUESTED_STATE);</p>
]]></description><link>https://forum.qt.io/post/723421</link><guid isPermaLink="true">https://forum.qt.io/post/723421</guid><dc:creator><![CDATA[AbhiVarma]]></dc:creator><pubDate>Mon, 01 Aug 2022 06:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 01 Aug 2022 06:10:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhivarma">@<bdi>AbhiVarma</bdi></a> Why?<br />
Why don't you do it in a clean way as I suggested?<br />
But it is up to you to write dirty code which may fail...</p>
]]></description><link>https://forum.qt.io/post/723413</link><guid isPermaLink="true">https://forum.qt.io/post/723413</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 01 Aug 2022 06:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 01 Aug 2022 04:45:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> what if i do the following.</p>
<pre><code>do
    {
    qAppObject-&gt;processEvents(QEventLoop::WaitForMoreEvents, 500);
    }
    while(m_eApiCallResponseState  != RESPONSE_REQUESTED_STATE);
</code></pre>
]]></description><link>https://forum.qt.io/post/723410</link><guid isPermaLink="true">https://forum.qt.io/post/723410</guid><dc:creator><![CDATA[AbhiVarma]]></dc:creator><pubDate>Mon, 01 Aug 2022 04:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 11:04:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhivarma">@<bdi>AbhiVarma</bdi></a> Well, how should your app receive the response if it is closed? It has to wait for the response...</p>
]]></description><link>https://forum.qt.io/post/722559</link><guid isPermaLink="true">https://forum.qt.io/post/722559</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 25 Jul 2022 11:04:12 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 10:14:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> Thanks for the solution. It working now. But i would like to understand why we have to make calls and get all the responses before window closes</p>
]]></description><link>https://forum.qt.io/post/722552</link><guid isPermaLink="true">https://forum.qt.io/post/722552</guid><dc:creator><![CDATA[AbhiVarma]]></dc:creator><pubDate>Mon, 25 Jul 2022 10:14:36 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 07:10:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhi_varma">@<bdi>Abhi_Varma</bdi></a> said in <a href="/post/722519">QNetworkAccessManager object not receiving the response when closing application</a>:</p>
<blockquote>
<p dir="auto">i was waiting for 30 seconds  to 1 min</p>
</blockquote>
<p dir="auto">Blocking the event loop? This is not something you should do in an event driven applications.  As long as event loop is blocked your slots will not be called.</p>
]]></description><link>https://forum.qt.io/post/722521</link><guid isPermaLink="true">https://forum.qt.io/post/722521</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 25 Jul 2022 07:10:07 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 07:08:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> before accepting the event i was waiting for 30 seconds  to 1 min but still i didnt get finished signal even though server sent me response.</p>
]]></description><link>https://forum.qt.io/post/722519</link><guid isPermaLink="true">https://forum.qt.io/post/722519</guid><dc:creator><![CDATA[Abhi_Varma]]></dc:creator><pubDate>Mon, 25 Jul 2022 07:08:09 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 06:55:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhivarma">@<bdi>AbhiVarma</bdi></a> said in <a href="/post/722511">QNetworkAccessManager object not receiving the response when closing application</a>:</p>
<blockquote>
<p dir="auto">before accepting the event</p>
</blockquote>
<p dir="auto">That's the point: you should NOT accept the event, because else your app is closed. Ignore the event. As sson as you get the response close the application (you will get closeEvent again, so you will need to remember that you already got the response and accept the event).</p>
]]></description><link>https://forum.qt.io/post/722513</link><guid isPermaLink="true">https://forum.qt.io/post/722513</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 25 Jul 2022 06:55:50 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 06:53:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I have tried to call the api call from MainWindow closeEvent before accepting the event but still im not getting the response</p>
<p dir="auto">Do you have any suggested method for debugging the network manager.</p>
]]></description><link>https://forum.qt.io/post/722511</link><guid isPermaLink="true">https://forum.qt.io/post/722511</guid><dc:creator><![CDATA[AbhiVarma]]></dc:creator><pubDate>Mon, 25 Jul 2022 06:53:54 GMT</pubDate></item><item><title><![CDATA[Reply to QNetworkAccessManager object not receiving the response when closing application on Mon, 25 Jul 2022 06:21:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhivarma">@<bdi>AbhiVarma</bdi></a> You should override closeEvent like shown in <a href="https://stackoverflow.com/questions/17480984/qt-how-do-i-handle-the-event-of-the-user-pressing-the-x-close-button" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/17480984/qt-how-do-i-handle-the-event-of-the-user-pressing-the-x-close-button</a> and delay the closing. Else your app is closed before it gets the response.</p>
]]></description><link>https://forum.qt.io/post/722506</link><guid isPermaLink="true">https://forum.qt.io/post/722506</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 25 Jul 2022 06:21:34 GMT</pubDate></item></channel></rss>