Note that there are some explanatory texts on larger screens.

plurals
  1. POConnecting signals/slots on separate thread using QtConcurrent::run
    text
    copied!<p>In my application I have the following code in a dialog:</p> <pre><code>connect(drive, SIGNAL(FileProgressChanged(Progress)), SLOT(OnFileProgressChanged(Progress))); QtConcurrent::run(this, &amp;ProgressDialog::PerformOperation, Operation, *Path, OutPath, drive); </code></pre> <p>The PerformOperation function eventually calls to a function in <code>drive</code> which emits the signal <code>FileProgressChanged</code>, and my <code>OnFileProgressChanged</code> function is as follows:</p> <pre><code>void ProgressDialog::OnFileProgressChanged(Progress p) { if (ui-&gt;progressCurrent-&gt;maximum() != p.Maximium) ui-&gt;progressCurrent-&gt;setMaximum(p.Maximium); ui-&gt;progressCurrent-&gt;setValue(p.Current); if (ui-&gt;groupBoxCurrent-&gt;title().toStdString() != p.FilePath) ui-&gt;groupBoxCurrent-&gt;setTitle(QString::fromStdString(p.FilePath)); } </code></pre> <p>I was doing some reading and saw that <a href="http://doc.qt.nokia.com/4.7-snapshot/qfuture.html" rel="nofollow">QFuture</a> and <a href="http://doc.qt.nokia.com/4.7-snapshot/qfuturewatcher.html" rel="nofollow">QFutureWatcher</a> support monitoring progress values (which would work great in this situation!), but those cannot be used in conjunction with <code>QtConcurrent::run</code>.</p> <p>How would I go about connecting the signal that gets moved emitted on the separate thread to the slot on my main thread so I can monitor the progress of the function called on the emitter thread?</p> <p>*<em>Edit -- *</em> I actually found an error with my code, but it doesn't seem to have an affect. I forgot to add <code>this</code> as an argument after the signal</p> <pre><code>connect(drive, SIGNAL(FileProgressChanged(Progress)), this, SLOT(OnFileProgressChanged(Progress))); </code></pre>
 

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