[Qt-interest] QtConcurrent::Exception

Sylvain Pointeau sylvain.pointeau at gmail.com
Thu May 7 16:36:04 CEST 2009


why don't you catch your exception from the specified thread and send an
event to your main thread?
you should really avoid thinking exceptions with threads.

Cheers,
Sylvain


On Thu, May 7, 2009 at 4:25 PM, Niklaus Hersche <niklaus.hersche at gesys.ch>wrote:

> Hi,
>
> Thanks for answering.
>
> Meanwhile i figured out how to do it.
>
>
> It only works, if you throw the exception from within an eventhandler.
> This presupposes, that the thraed has an eventloop ( call exec()).
>
> You can try/catch in QApplication::notify
>
> e.g:
> ************************************************************
> virtual bool notify(QObject *p_sender, QEvent *p_event) {
>  try {
>    return QApplication::notify(p_sender, p_event);
>  }catch(const MyXeption &e) {
>    QThread *currentThread = QThread::currentThread();
>    if(currentThread != thread()) {
>      // l'exception à été lancé dans une autre thread
>      // il n'est donc pas possible d'afficher d'éléments graphique ici ...
>      qDebug() << "MyXeption caught:" << e.what();
>    } else {
>      // l'exception à été lancé dans la thread principale
>        // on peut donc afficher un dialog ...
>      qDebug() << "MyXeption caught:" << e.what();
>    }
>  }
> }
> ************************************************************
> See also http://forum.qtfr.org/viewtopic.php?id=7615
>
> Cheers
> Nik
>
> ________________________________________
> Von: Sylvain Pointeau [mailto:sylvain.pointeau at gmail.com]
> Gesendet: Donnerstag, 7. Mai 2009 15:31
> An: Niklaus Hersche
> Cc: qt-interest at trolltech.com
> Betreff: Re: [Qt-interest] QtConcurrent::Exception
>
> I don't think that the exceptions in C++ can be thrown in one thread and
> catched in another.
>
> Cheers,
> Sylvain
> On Wed, May 6, 2009 at 2:18 PM, Niklaus Hersche <niklaus.hersche at gesys.ch>
> wrote:
> Hi,
>
> In a worker thread I want to throw a QtConcurrent::Exception and catch it
> in
> the main thread.
>
>
> According the documentation,
>
> " Base class for exceptions that can transferred across threads"
>
> this should be possible.
>
> Does anybody know how to implement it ?
>
>
> Regards
> Nik
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090507/c8c74479/attachment.html 


More information about the Qt-interest-old mailing list