[Qt-interest] install message handler

Arnold Krille arnold at arnoldarts.de
Thu Sep 2 12:09:58 CEST 2010


Hi,

On Thursday 02 September 2010 11:45:33 Sean Harmer wrote:
> Then just call setupDebugRedirection() somewhere in main(). We used a mutex
> in the msg handler function because we were usign qDebug() and friends
> from several threads and QTextStream is not thread-safe.
> NB This took us a long time to realise. We thought we had a race condition
> somewhere else in our threading code and the more qDebug() statements we
> added the worse the problem got. We had forgotten about the innocent
> looking msg handler function. Oh well, lesson learned ;-)

The "easiest" solution to this is to make the handler write into a ring-buffer 
and create another thread (or maybe even another process coupled via shared 
memory) to read and print from this ring-buffer. If you have several apps in 
that project, you could even create a debug-daemon that stays persistent 
during the debug-sessions.
If you just use a thread for printing, you have to add a shutdown handler to 
stop that thread and even wait for that thread to print all the backlog. Not 
trivial in case of errors, but its doable...

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100902/994b81e9/attachment.bin 


More information about the Qt-interest-old mailing list