PDA

View Full Version : QProgressDialog::setValue crash( Mac )



marcel
11th April 2007, 17:54
Has anyone experienced any crashes in setValue?

QProgressDialog::setValue is called after receiving a custom event posted from another thread in the GUI thread. It does not crash every time( it has its moments :) ).

Thanks.

wysota
11th April 2007, 17:56
Do you call it from the GUI thread? Do you call any GUI related methods from within a worker thread?

marcel
11th April 2007, 18:02
No, of course there aren't any GUI calls from the other thread.
setValue is called from an event(...) method. The value to be set comes with the custom event, from the worker thread.
This is why it's so weird...

Also, I haven't set the progress dialog to be Window Modal, because this would have caused QApplication::processEvents() to be called from setValue.

wysota
11th April 2007, 19:44
Can we see the handler code?

marcel
11th April 2007, 20:14
I am not at work right now, but I can reproduce it:



bool MyWidget::event( QEvent *e )
{
if( e->type() == QEvent::User )
{
MyEvent *customEvent = dynamic_cast<MyEvent*>(e);
if( customEvent && mProgressDlg )
{
if( customEvent->id == MyEvent::eUpdateProgress )
mProgressDlg->setValue( customEvent->progressValue );
else if( customEvent->id == MyEvent::eDone )
{
mProgressDlg->reset();
delete mProgressDlg;
mProgressDlg = NULL;
// ... Other code
}
e->accept();
return true;
}
}

return false;
}
mProgressDlg is of type QProgressDialog* and is created with:



mProgressDlg = new QProgressDialog( "...", "...", 0, 100, mainWindow, 0 );
mProgressDlg->setMinimumDuration( 2000 );
mProgressDlg->setValue( 0 );
mProgressDlg->setAutoClose( true );
where mainWindow is a pointer to my app QMainWindow. Does QProgressDialog posts some events (maybe QTimerEvent's ?? ) to it's parent event queue?

So, this is a minimal version of the code. I hope I didn't forget anything.

Thanks.

wysota
11th April 2007, 20:23
First of all I don't see you call the base implementation of event(). Second of all, is there a special reason why you handle the event in event() instead of customEvent()?

marcel
11th April 2007, 20:27
Ok.

1. The base impl of event() is called, just forgot it here :).
2. No reason at all for handling this in event(). Is there any major difference between customEvent() and event(), except the fact that only user defined events enter customEvent()?

wysota
11th April 2007, 23:12
Probably no "major" difference, but still you should handle the event in customEvent() :) I doubt that will change your situation - I can't see anything wrong with the code but it's worth to try. Is it possible for you to isolate and stop the other threads so that only the GUI thread runs and see if the application still crashes? If not, at least try debugging with a debugger and print a backtrace of the crash.