PDA

View Full Version : QObject::timerEvent and exceptions



krivenok
15th March 2006, 11:36
Hello all!

This is timerEvent of my MainWindow class

void MainWindow::timerEvent ( QTimerEvent * event )
{
/// Filter events (I am only interested in events from my timer)
if (timerId_ == event->timerId() )
{
try
{
/// Problem code here
}
catch(MyAppCriticalError& e)
{
/// Kill my timer by ID
killTimer(timerId_);
/// Show message
QMessageBox::information(0, "My app", "Critical error");
/// Throw another exception
throw MyAppTerminate(1,e.what());
}
}//if
}//timerEvent

My questions are:
1) Is this code correct (in generally of course)?
2) Can I throw exception inside timer event handler?

fullmetalcoder
15th March 2006, 12:16
1) IMHO you should use a timer object not directly its id

2) I guess so but who will catch them??? You've got to reimplement the event(QEvent *e) function.

3) Next time, use the tag (without the underscore of course)