Note that there are some explanatory texts on larger screens.

plurals
  1. POQNetworkAccessManager threads never finish
    primarykey
    data
    text
    <p>I know that in version 4.8 each http request gets its own thread to run.<br> I'm doing a links checker app that does a lot of http requests in a while loop and I notice in the windows task manager that my app is using more than 1600 threads over time and the number never goes down, only up until it crashes the app. (I'm guessing that is the cause.)</p> <p>My question is, does <code>QNetworkAccessManager</code> have an option to use thread pool?<br> Or does it have an option to clean its threads after it finishes its http request?</p> <p>This is the main loop:</p> <pre><code>while(!rpm_urlStack-&gt;isEmpty()) { QString url = rpm_urlStack-&gt;top(); //define the reply QNetworkReply *reply; rpm_urlStack-&gt;pop(); QString urlForReq(url); bool returnVal = true; QNetworkRequest request; request.setUrl(QUrl(urlForReq)); request.setRawHeader("User-Agent", USER_AGENT.toUtf8()); request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setRawHeader("Accept-Language", "en-us,en;q=0.5"); request.setRawHeader("Connection", "Keep-Alive"); QEventLoop loop; reply = m_networkManager-&gt;get(request); connect(reply, SIGNAL(finished()), &amp;loop, SLOT(quit())); loop.exit(); if(!loop.isRunning()) { loop.exec(); } RequestFinishedHandler(reply); // this is how I delete the reply object delete reply; } RequestFinishedHandler(QNetworkReply *reply) { if (reply-&gt;error() &gt; 0) { QNetworkReply::NetworkError networkError = reply-&gt;error(); QString err = reply-&gt;errorString(); } else { QVariant vStatusCodeV = reply-&gt;attribute(QNetworkRequest::HttpStatusCodeAttribute); QMutexLocker lock(_pMutex); // _pMutex defined as class member char *buffer; buffer = getCurrentDateTime(); QTextStream out(m_file); out &lt;&lt; buffer &lt;&lt; " " &lt;&lt; _sCurrentUrl &lt;&lt; "\n"; lock.unlock(); if(vStatusCodeV.toInt() == 200) { QString ApiResponse; QByteArray data; data=reply-&gt;readAll(); ApiResponse.append(QString::fromUtf8(data)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload