[clug] long run function in trolltech qt widget

jm jeffm at ghostgun.com
Fri Dec 5 03:11:09 GMT 2008

> Luckily this assumption holds. I got the thread version going 
> yesterday, but the problem now is that it runs multiple times.  The 
> thread start method it called from within the wizard's page 
> showevent() method, but it seems that in the course of things it 
> receives multiple QEvent::Show events. I've tried various way of 
> having it run only once, but seem to be missing something. At the 
> moment the code is something similar to

I think I may have found the fix. Changing
>  // QThread emits finished when run() completes
>  connect(genThread, SIGNAL(finished()), this, SIGNAL(completeChanged()));


connect(genThread, SIGNAL(finished()), this, SLOT(generateFinished()));

and adding the slot

void GenPage::generateFinished()
 std::cout << "generateFinished()" << std::endl;
  complete = true;
  emit completeChanged();

seems to work even though the Trolltech's example and documentation seem 
to suggest the former should work. If there is a cleaner way to 
accomplish the effect I'm after feel free to comment.

Also, is there an alternative to the QProgressBar? It's not possible to 
tell ahead of time how many times the call back function will be called. 
Is it possible to have a spinning wheel? Is there a ProgressBall?


More information about the linux mailing list