[clug] long run function in trolltech qt widget
jm
jeffm at ghostgun.com
Wed Dec 3 22:50:11 GMT 2008
Brad Hards wrote:
>
> The normal approach would be to connect the accepted() signal to a custom slot
> that executes long_run().
>
> However to show any GUI stuff changing, you need to return to the event loop.
> How is long_run() returning control to the event loop? Are you dividing up
> the run into multiple steps, or are using some kind of threading approach?
>
>
I have code similar to,
MyPage::MyPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("Do the work"));
......
progress = new QProgressBar(this);
progress->setMaximum(100);
......
}
extern "C" void callback(void *arg)
{
QProgressBar *bar = (QProgressBar *)arg;
printf("doing work\");
bar->setValue(bar->value() + 1);
}
MyPage::doWork()
{
progress->setValue(0);
result = long_run(callback, (void *) progress)
}
MyPage::isComplete()
{
// To be done
return true;
}
doWork() doesn't return until it's actually finished the calculation.
There isn't a contiuation unfortunately. How do I call doWork() so that
MyPage is displayed while the work is being done? I've been trying to
avoid a thread for this as it only meant to be a prototype at this stage
and QThread looks as if it will take a while to understand. Especially
getting values in and out of threads.
Jeff.
More information about the linux
mailing list