[clug] long run function in trolltech qt widget

Michael Cohen scudette at gmail.com
Wed Dec 3 22:53:31 GMT 2008


You could always use another process with fork/clone and friends. Use
shared memory to pass results back. Tridge's and rusty's talk about
why threads are evil might shed light on the issue.

Michael.

On Thu, Dec 4, 2008 at 9:50 AM, jm <jeffm at ghostgun.com> wrote:
>
>
> 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.
>
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux
>


More information about the linux mailing list