<?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[[Solved]How can I pause download in QEventLoop?]]></title><description><![CDATA[<p dir="auto">I have downloader and want to add pause/resume/abort functions, abortion is simple but I got stuck with pausing.<br />
I have list of URLs so I run it in for loop and for reply I wait in QEventLoop. I wanted to connect clicked() signal of my button to pause slot with another QEventLoop where I wait till another button is pressed (resume or abort). But soon I released that won't work and now I am (again) stuck.<br />
there is the loop<br />
@<br />
for(int b=0;b&lt;urls4Download.count();b++){<br />
if(!folder.endsWith("/"))folder.append("/");<br />
QString st = <a href="http://FileList.at" target="_blank" rel="noopener noreferrer nofollow ugc">FileList.at</a>(fileIndex[b]);<br />
st.replace(QRegExp("/"),QString("<em>"));<br />
file=new QFile(folder+st);<br />
file-&gt;open(QIODevice::WriteOnly);<br />
reply=nam.get(QNetworkRequest(QUrl(<a href="http://urls4Download.at" target="_blank" rel="noopener noreferrer nofollow ugc">urls4Download.at</a>(b))));<br />
QEventLoop loop;<br />
connect(reply, SIGNAL(finished()), &amp;loop, SLOT(quit()));<br />
connect(reply,SIGNAL(finished()),this,SLOT(saveFile()));<br />
connect(reply,SIGNAL(readyRead()),this,SLOT(readyReadFile()));<br />
connect(ui-&gt;pushButton_stop,SIGNAL(clicked()),&amp;loop,SLOT(quit()));<br />
connect(ui-&gt;pushButton_stop,SIGNAL(clicked()),this,SLOT(abort()));<br />
connect(ui-&gt;pushButton_pause,SIGNAL(clicked()),this,SLOT(pause()));<br />
loop.exec();<br />
@<br />
pause() function is here<br />
@<br />
void MainWindow::pause(){<br />
QEventLoop loop</em>;<br />
connect(ui-&gt;pushButton_play,SIGNAL(clicked()),&amp;loop_,SLOT(quit()));  //button<br />
connect(ui-&gt;actionResume,SIGNAL(triggered()),&amp;loop_,SLOT(quit()));  //there is same option in menu too<br />
connect(ui-&gt;pushButton_stop,SIGNAL(clicked()),&amp;loop_,SLOT(quit()));<br />
connect(ui-&gt;pushButton_stop,SIGNAL(clicked()),this,SLOT(abort()));   //in case user doesn't want resume<br />
loop_.exec();<br />
}<br />
@<br />
I see I have to quit QEventLoop in case I want to pause it and then wait until resume button (or stop) is pressed but how can I resume when it is in for loop? I was thinking about goto statement and put identifier before QEventLoop so I can return there after button press but that doesn't seems as good idea.</p>
]]></description><link>https://forum.qt.io/topic/24832/solved-how-can-i-pause-download-in-qeventloop</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 03:06:46 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/24832.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Mar 2013 19:18:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved]How can I pause download in QEventLoop? on Tue, 05 Mar 2013 23:07:43 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="SetBetterPass" date="1362479708"]So if I have understood it right I have to count bytes already transmitted each time readyReadFile() is called, and if pause is requested break the loop, save actual value of b in int b_value (set it to 0 by default) too so I can return to for loop and set loop to actual position of b (for(int b=b_value;...)) and set header like this :<br />
[/quote]</p>
<p dir="auto">No need to keep a count of received bytes (unless you use it for something else)  or store that somewhere between pause and resume.  Write received bytes to an actual file as they are received and close the file when paused.  On resume open the partial file for append and use the actual file size to determine where to resume from.<br />
This is what Code_ReaQtor's example does also.</p>
]]></description><link>https://forum.qt.io/post/169255</link><guid isPermaLink="true">https://forum.qt.io/post/169255</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Tue, 05 Mar 2013 23:07:43 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved]How can I pause download in QEventLoop? on Tue, 05 Mar 2013 10:50:21 GMT]]></title><description><![CDATA[<p dir="auto">I found this months ago, but you need to reimplement it with your QEventLoop beacuse it was designed to be asynchronous.</p>
<p dir="auto">"<a href="http://kunalmaemo.blogspot.com" target="_blank" rel="noopener noreferrer nofollow ugc">kunalmaemo.blogspot.com</a>":<a href="http://kunalmaemo.blogspot.com/2011/07/simple-download-manager-with-pause.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://kunalmaemo.blogspot.com/2011/07/simple-download-manager-with-pause.html</a><br />
"<a href="http://kunalmaemo.blogspot.com" target="_blank" rel="noopener noreferrer nofollow ugc">kunalmaemo.blogspot.com</a>":<a href="http://kunalmaemo.blogspot.com/2010/05/simple-download-manager-in-qt-with.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://kunalmaemo.blogspot.com/2010/05/simple-download-manager-in-qt-with.html</a></p>
]]></description><link>https://forum.qt.io/post/169184</link><guid isPermaLink="true">https://forum.qt.io/post/169184</guid><dc:creator><![CDATA[Code_ReaQtor]]></dc:creator><pubDate>Tue, 05 Mar 2013 10:50:21 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved]How can I pause download in QEventLoop? on Tue, 05 Mar 2013 10:35:08 GMT]]></title><description><![CDATA[<p dir="auto">So if I have understood it right I have to count bytes already transmitted each time readyReadFile() is called, and if pause is requested break the loop, save actual value of b in int b_value (set it to 0 by default) too so I can return to for loop and set loop to actual position of b (for(int b=b_value;...)) and set header like this :<br />
@<br />
QNetworkRequest request;<br />
request.setUrl(QUrl(<a href="http://urls4Download.at" target="_blank" rel="noopener noreferrer nofollow ugc">urls4Download.at</a>(b));<br />
request.setRawHeader("Range",byteCount);<br />
reply=nam.get(request)));@</p>
<p dir="auto">I have no time to try it right now so it may help if I am wrong someone correct me till I come back to computer :)</p>
]]></description><link>https://forum.qt.io/post/169182</link><guid isPermaLink="true">https://forum.qt.io/post/169182</guid><dc:creator><![CDATA[SetBetterPass]]></dc:creator><pubDate>Tue, 05 Mar 2013 10:35:08 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved]How can I pause download in QEventLoop? on Mon, 04 Mar 2013 23:25:50 GMT]]></title><description><![CDATA[<p dir="auto">Pausing does not hold open a connection and simply stop talking (transmitting acknowledgements).</p>
<p dir="auto">The typical pause/resume download functionality in a web browser uses the server's HTTP 1.1 byte range capability to resume a download  from part way through a resource.  "Pausing" actually terminates the connection but does not discard the partial file.  "Resuming" is actually a whole new request for the same file with a specified byte range (Range header) that starts at the byte after the last one in the partial file.  The incoming data from the new request is appended to the existing partial file.</p>
<p dir="auto">Have a look at [url=http://tools.ietf.org/html/rfc2616#section-14.35.2]RFC  2616 Section 14.35.2[/url] for the gory details.</p>
]]></description><link>https://forum.qt.io/post/169140</link><guid isPermaLink="true">https://forum.qt.io/post/169140</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Mon, 04 Mar 2013 23:25:50 GMT</pubDate></item></channel></rss>