Note that there are some explanatory texts on larger screens.

plurals
  1. POQThread finished() signal is never emited
    primarykey
    data
    text
    <p>so i have a worker class that has 2 slots: StartWork() and StopWork(), the StartWork() one runs an infinite loop (it just reads and reads camera input non-stop) and the StopWork() method just sets a bool variable to false (so the loop inside StartWork() stops).</p> <p>according to the QThread documentation, the best way to use them now is not by sub-classing but by moving workers into the thread, so that's what i do. problem is, the started() signal from the thread gets called but the finished() signal never gets called.</p> <p>worker class slots:</p> <blockquote> <p>void StartWork(){ running = true; while(running){ do work; }}</p> <p>void StopWork(){ running = false; }</p> </blockquote> <p>QThread initialization and signal/slot connection:</p> <pre><code>thread = new QThread(); worker = new Worker(); worker.moveToThread(thread); QObject::connect(thread, SIGNAL(started()), worker, SLOT(StartWork())); QObject::connect(thread, SIGNAL(finished()), worker, SLOT(StopWork())); </code></pre> <p>and on my QPushButton i do this:</p> <pre><code>if(pushStartStop-&gt;text().toLower() == "start") { pushStartStop-&gt;setText("Stop"); thread-&gt;start(); } else { pushStartStop-&gt;setText("Start"); thread-&gt;quit(); } </code></pre> <p>the thread->start() works fine, and the StartWork() gets called and everything is beautiful (GUI runs with no blocks, etc).</p> <p>but thread->quit() doesn't do anything, it gets called (because the button changes text) but thats it. if i just call worker->StopWork() it works, but then i can't start it again.</p> <p>I've tried with thread->exit(); but the results are the same. Also i know sub-classing works, but it looks uglier and according to the recent Qt documentation, sub-classing is no longer optimal.</p> <p>thanks in advance.</p>
    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.
    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