<?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[Wait&#x2F;sleep 100ms during QPixmap in QLabel slideshow]]></title><description><![CDATA[<p dir="auto">Hi again :)</p>
<p dir="auto">I want to create an image slideshow, by waiting 100ms between the displayed pics. The pictures are displayed as QPixmap's in  a QLabel. The slideshow should start when I'm clicking on the pushButton.</p>
<pre><code>std::vector&lt;QPixmap&gt; pics;
//.......

void MainWindow::on_pushButton_clicked()
{
        for(const QPixmap&amp; x: pics){
            ui-&gt;label-&gt;setPixmap(x);
            //wait 100ms between each pic
        }
}
</code></pre>
<p dir="auto">I've tried using QThread::msleep(100); but this freezes the program 100*nr. of pics ms and displays the last image only.</p>
]]></description><link>https://forum.qt.io/topic/69983/wait-sleep-100ms-during-qpixmap-in-qlabel-slideshow</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 14:06:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/69983.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 06 Aug 2016 16:15:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wait&#x2F;sleep 100ms during QPixmap in QLabel slideshow on Sat, 06 Aug 2016 20:19:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cpper">@<bdi>cpper</bdi></a><br />
ok. super.<br />
Nope, in this case using non pointers is very correct since<br />
there is no need for pointers here. :)</p>
]]></description><link>https://forum.qt.io/post/341087</link><guid isPermaLink="true">https://forum.qt.io/post/341087</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sat, 06 Aug 2016 20:19:22 GMT</pubDate></item><item><title><![CDATA[Reply to Wait&#x2F;sleep 100ms during QPixmap in QLabel slideshow on Sat, 06 Aug 2016 20:02:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
It's clear now.</p>
<p dir="auto">Since I want to keep everything in the clicked() function (and not call update() slot) I used both QTimer and QEventLoop:</p>
<pre><code>
void MainWindow::on_pushButton_clicked()
{
    QTimer timer(this);
    QEventLoop loop;
    timer.setInterval(100);
    QObject::connect(&amp;timer, &amp;QTimer::timeout,&amp;loop,&amp;QEventLoop::quit);

    for(const QPixmap&amp; x: pics){
        ui-&gt;label-&gt;setPixmap(x);
        timer.start();
        loop.exec();
    }



}
</code></pre>
<p dir="auto">It works as I wished now. But would it be better to use  pointer to QTimer and QEventLoop in such situations ?</p>
]]></description><link>https://forum.qt.io/post/341084</link><guid isPermaLink="true">https://forum.qt.io/post/341084</guid><dc:creator><![CDATA[cpper]]></dc:creator><pubDate>Sat, 06 Aug 2016 20:02:18 GMT</pubDate></item><item><title><![CDATA[Reply to Wait&#x2F;sleep 100ms during QPixmap in QLabel slideshow on Sat, 06 Aug 2016 19:54:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cpper">@<bdi>cpper</bdi></a><br />
well you pause the GUI thread with msleep.</p>
<p dir="auto">The reason you dont see each image is that the for loop<br />
don't allow events to be processed.</p>
<p dir="auto">You can use  QApplication::processEvents();<br />
in the loop and it will sort of work - but you will still make the<br />
GUI a big laggy as long for loops in gui thread is just not a good idea.</p>
]]></description><link>https://forum.qt.io/post/341083</link><guid isPermaLink="true">https://forum.qt.io/post/341083</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sat, 06 Aug 2016 19:54:52 GMT</pubDate></item><item><title><![CDATA[Reply to Wait&#x2F;sleep 100ms during QPixmap in QLabel slideshow on Sat, 06 Aug 2016 19:05:31 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, I'll try this method. However, is there no simpler way to do it ? Such as a single function call. Why doesn't msleep work in this case ?</p>
]]></description><link>https://forum.qt.io/post/341082</link><guid isPermaLink="true">https://forum.qt.io/post/341082</guid><dc:creator><![CDATA[cpper]]></dc:creator><pubDate>Sat, 06 Aug 2016 19:05:31 GMT</pubDate></item><item><title><![CDATA[Reply to Wait&#x2F;sleep 100ms during QPixmap in QLabel slideshow on Sat, 06 Aug 2016 18:10:24 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
You could use a timer and a slot and do it sort of reverse</p>
<p dir="auto">in constructor<br />
QTimer *timer = new QTimer(this);<br />
connect(timer, SIGNAL(timeout()), this, SLOT(update()));<br />
timer-&gt;start(1000);<br />
..</p>
<p dir="auto">// this is called every second. adjust if need to be faster/slower<br />
void MainWindow::update()<br />
{<br />
if (currentimage &lt;pics.size() )<br />
ui-&gt;label-&gt;setPixmap( pics[ currentimage++ ] );</p>
<p dir="auto">}</p>
]]></description><link>https://forum.qt.io/post/341078</link><guid isPermaLink="true">https://forum.qt.io/post/341078</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sat, 06 Aug 2016 18:10:24 GMT</pubDate></item></channel></rss>