Note that there are some explanatory texts on larger screens.

plurals
  1. POQt thread and loop issue
    text
    copied!<p>this is the run method of a subclass of QThread:</p> <pre><code>void crono::Controller::run() { //initialise timer int *i = &amp; this-&gt;model-&gt;seconds_elapsed; for (*i = 0; *i &lt; this-&gt;model-&gt;seconds_total; (*i)++) { //calculate current seconds/minutes/hours elapsed starting from seconds_elapsed (*i) this-&gt;model-&gt;tick(); //should display in the form the time elapsed this-&gt;vista-&gt;showTime(); sleep(1000); } Beep(1000, 500); //beep when all is over } </code></pre> <p>the controller updates the model values.</p> <p>The QT form is opened on start, I guess in the main application thread.</p> <p>The issue is that despise on debug *i=0 and seconds_total = X > 0, the loop is executed only one time, after the first time the debug halt (it does not end), the forms pops up but nothing happens.</p> <p>The only thing I can guess of, is that the Controller Thread lose its priority and never gains the cpu again. </p> <p>How can avoid this?</p> <p><em><strong>EDIT</em></strong> I am trying using QTimer, with bad luck.</p> <p>i declared update as a public slot, and then implemented like this:</p> <pre><code>void crono::Controller::update() { this-&gt;modello-&gt;tick(); this-&gt;vista-&gt;showTime(); //eventually stop at some point (pointer to timer and timer-&gt;stop()? //... //Beep(1000, 500); } </code></pre> <p>And I inserted the QTimer in the controller (thread) object instead of the loop cycle:</p> <pre><code>void crono::Controller::run() { //inizializzo timer int *i = &amp; this-&gt;modello-&gt;secondi_trascorsi; QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()),this, SLOT(update())); timer-&gt;start(1000); } </code></pre> <p>I do not know why, but the update() method is never called, instead of being called an infinite number of times. Why?</p>
 

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