<?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[How? I show a message, while the task is running]]></title><description><![CDATA[<p dir="auto">Hi guys, I have the following code.</p>
<p dir="auto">A method compress (), where I do the task of compressing an entire directory, I call this method from my button, with a QtConcurrent, as you can see. so far so good.</p>
<p dir="auto">My question is, how can I display a message while compressing the folder is running.</p>
<p dir="auto">I am using QuaZIP, for the compression process.</p>
<pre><code>#ifndef WIDGET_H
#define WIDGET_H

#include &lt;QWidget&gt;

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
  Q_OBJECT

public:
  Widget(QWidget *parent = nullptr);
  ~Widget();
 
private slots:
  void on_pushButton_5_clicked();

private:
  Ui::Widget *ui;
  void compress();
public:
 
};
#endif // WIDGET_H

</code></pre>
<pre><code>#include "widget.h"
#include "ui_widget.h"
#include &lt;QMessageBox&gt;
#include &lt;QDebug&gt;
#include &lt;JlCompress.h&gt;
#include &lt;QtConcurrent/QtConcurrent&gt;
#include &lt;QFuture&gt;

Widget::Widget(QWidget *parent)
  : QWidget(parent), ui(new Ui::Widget)
{
  ui-&gt;setupUi(this); 
}
Widget::~Widget()
{
  delete ui;
}
void Widget::on_pushButton_5_clicked()
{
  QGuiApplication::setOverrideCursor(Qt::WaitCursor);
  QFuture&lt;void&gt; future=QtConcurrent::run(this,&amp;Widget::compress);
  future.waitForFinished();
  QGuiApplication::restoreOverrideCursor();
  QMessageBox::information(this,qApp-&gt;applicationName(),"The folder was compressed successfully.");
}
void Widget::compress()
{
  if(!JlCompress::compressDir("C:/Users/Mypc/Desktop/iconos.zip", "D:/images/iconos")){
    QMessageBox::warning(this,qApp-&gt;applicationName(),"Error compressing folder.");
    return;
  }
}

</code></pre>
]]></description><link>https://forum.qt.io/topic/129560/how-i-show-a-message-while-the-task-is-running</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 15:06:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/129560.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 19 Aug 2021 20:43:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How? I show a message, while the task is running on Tue, 24 Aug 2021 22:24:17 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk<br />
ok It gives me the same result</p>
]]></description><link>https://forum.qt.io/post/677564</link><guid isPermaLink="true">https://forum.qt.io/post/677564</guid><dc:creator><![CDATA[lincoln]]></dc:creator><pubDate>Tue, 24 Aug 2021 22:24:17 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Sat, 21 Aug 2021 08:48:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lincoln">@<bdi>Lincoln</bdi></a> remove the</p>
<pre><code>QMessageBox::warning(this,qApp-&gt;applicationName(),"Error al comprimir la carpeta.");
</code></pre>
<p dir="auto">from compress</p>
<p dir="auto">no gui stuff in other threads.</p>
]]></description><link>https://forum.qt.io/post/676937</link><guid isPermaLink="true">https://forum.qt.io/post/676937</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Sat, 21 Aug 2021 08:48:41 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 19:17:20 GMT]]></title><description><![CDATA[<p dir="auto">Are you sure that compress is called ?<br />
How many times ?<br />
How fast ?<br />
Any runtime warning related to signals and slots ?<br />
Why are you using map since your compress method takes a list as parameter ?</p>
]]></description><link>https://forum.qt.io/post/676896</link><guid isPermaLink="true">https://forum.qt.io/post/676896</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 20 Aug 2021 19:17:20 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 19:04:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
I mean when removing box.deleteLater (); as <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> mentions, it does not close, and stays there. And I can't close the application either, the entire App is frozen.</p>
<p dir="auto">It seems to me that it is best to do it with QFutureWatcher, as I put in the code below, but it does not work either.</p>
]]></description><link>https://forum.qt.io/post/676893</link><guid isPermaLink="true">https://forum.qt.io/post/676893</guid><dc:creator><![CDATA[lincoln]]></dc:creator><pubDate>Fri, 20 Aug 2021 19:04:57 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 18:17:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">What do you mean by not responding ?</p>
]]></description><link>https://forum.qt.io/post/676885</link><guid isPermaLink="true">https://forum.qt.io/post/676885</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 20 Aug 2021 18:17:39 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 16:00:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a><br />
Already remove deletelater and the message box is stuck, not responding.</p>
]]></description><link>https://forum.qt.io/post/676874</link><guid isPermaLink="true">https://forum.qt.io/post/676874</guid><dc:creator><![CDATA[lincoln]]></dc:creator><pubDate>Fri, 20 Aug 2021 16:00:13 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 05:28:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lincoln">@<bdi>lincoln</bdi></a> said in <a href="/post/676740">How? I show a message, while the task is running</a>:</p>
<blockquote>
<p dir="auto">box.deleteLater();</p>
</blockquote>
<p dir="auto">Don't delete stack allocated objects!<br />
box will be deleted automatically as soon as on_pushButton_5_clicked() finishes.</p>
]]></description><link>https://forum.qt.io/post/676756</link><guid isPermaLink="true">https://forum.qt.io/post/676756</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 20 Aug 2021 05:28:16 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 04:16:09 GMT]]></title><description><![CDATA[<p dir="auto">Also try a ProgressDialog and QFutureWatcher as follows, but it doesn't compile, I get this error.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/ebd9741b-e4dd-4e23-80a5-906c10693553.png" alt="b214f7f4-da09-4cd4-99ff-eba3dea38d4d-image.png" class=" img-fluid img-markdown" /></p>
<pre><code>void Widget::on_pushButton_5_clicked()
{

  QStringList files;
  QDir dir("D:/images/iconos/uigenericicon");
  files=dir.entryList(QStringList() &lt;&lt; "*.jpg" &lt;&lt; "*.JPG"&lt;&lt;"*.PNG",QDir::Files);
  
  qInfo()&lt;&lt;files;

  QProgressDialog pDialog;
  pDialog.setLabelText("Porecessing!!");

  QFutureWatcher&lt;void&gt; watcher;

  QObject::connect(&amp;pDialog,SIGNAL(canceled()),&amp;watcher,SLOT(cancel()));
  QObject::connect(&amp;watcher,SIGNAL(finished()),&amp;pDialog,SLOT(reset()));
  QObject::connect(&amp;watcher,SIGNAL(progressRangeChanged(int,int)),&amp;pDialog,SLOT(setRange(int,int)));
  QObject::connect(&amp;watcher,SIGNAL(progressValueChanged(int)),&amp;pDialog,SLOT(setValue(int)));

  watcher.setFuture(QtConcurrent::map(files,&amp;Widget::compress));
  pDialog.exec();
  if(watcher.isCanceled()){
    QMessageBox::information(this,qApp-&gt;applicationName(),"You canceled.");
  }else{
    QMessageBox::information(this,qApp-&gt;applicationName(),"All done.");
  }
}

void Widget::compress(QStringList &amp;files)
{

  if(!JlCompress::compressFiles("C:/Users/Lincoln/Desktop/iconos.zip",files)){
    QMessageBox::warning(this,qApp-&gt;applicationName(),"Error al comprimir la carpeta.");
    return;
  }

}
</code></pre>
]]></description><link>https://forum.qt.io/post/676750</link><guid isPermaLink="true">https://forum.qt.io/post/676750</guid><dc:creator><![CDATA[lincoln]]></dc:creator><pubDate>Fri, 20 Aug 2021 04:16:09 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Fri, 20 Aug 2021 01:20:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
I did this, but now when the backup finishes, the entire application closes.</p>
<pre><code>void Widget::on_pushButton_5_clicked()
{

  QMessageBox box;
  //  box-&gt;setWindowFlags(Qt::Dialog | Qt::SplashScreen);
  box.setStandardButtons(QMessageBox::NoButton);
  box.setText("Realizando una tarea!");
  box.setWindowTitle(qApp-&gt;applicationName());
  box.setIcon(QMessageBox::Information);
  box.setAttribute(Qt::WA_DeleteOnClose);

  QFutureWatcher&lt;void&gt; watcher;

  QFuture&lt;void&gt; future=QtConcurrent::run(this,&amp;Widget::compress);
  watcher.setFuture(future);

  QGuiApplication::setOverrideCursor(Qt::WaitCursor);


  QObject::connect(&amp;watcher,&amp;QFutureWatcher&lt;void&gt;::finished,[&amp;](){

    box.close();
    box.deleteLater();
    QGuiApplication::restoreOverrideCursor();
  });
  box.exec();
  QMessageBox::information(this,qApp-&gt;applicationName(),"Carpeta comprimirda.");

}
</code></pre>
]]></description><link>https://forum.qt.io/post/676740</link><guid isPermaLink="true">https://forum.qt.io/post/676740</guid><dc:creator><![CDATA[lincoln]]></dc:creator><pubDate>Fri, 20 Aug 2021 01:20:16 GMT</pubDate></item><item><title><![CDATA[Reply to How? I show a message, while the task is running on Thu, 19 Aug 2021 20:48:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lincoln">@<bdi>lincoln</bdi></a> said in <a href="/post/676720">How? I show a message, while the task is running</a>:</p>
<blockquote>
<pre><code>QFuture&lt;void&gt; future=QtConcurrent::run(this,&amp;Widget::compress);
future.waitForFinished();
</code></pre>
</blockquote>
<p dir="auto">Display it after the <code>run()</code>, and don't do the <code>waitForFinished()</code> in the slot if you want the user to see it.</p>
]]></description><link>https://forum.qt.io/post/676722</link><guid isPermaLink="true">https://forum.qt.io/post/676722</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 19 Aug 2021 20:48:28 GMT</pubDate></item></channel></rss>