PDA

View Full Version : Using qDebug to write to an external file



qtUser500
16th November 2009, 15:02
I would like to use qDebug in my application, and have it write to an external Log file. This way I can check for messages when the application is running in 'release' mode.

The version of Qt I am using is 3.3.5 (:oI know it is outdated et al, but my project is on it). The qDebug notes in QtAssistant doesn't provide information on writing to an external file. I would like to know if this is possible, and how to do it.

Thanks in advance.

calhal
16th November 2009, 15:57
As written in QtAssistant, qDebug() calls the message handler and if no message handler has been installed, the message is simply printed on stderr. Thus you can either redirect stderr to a file while executing your application or install your custom handler (http://doc.trolltech.com/3.3/qapplication.html#qInstallMsgHandler).

Can't you just use QFile class?

qtUser500
16th November 2009, 17:57
Thanks calhal for your input.

Yes I can use QFile, but was wondering whether there was an inbuilt functionality in qDebug where I can both write to file as well as send it to output. So that it can be used both for release and debug modes of the application.

Well it looks like I will just need to stick to QFile instead. Thanks anyways!

wysota
16th November 2009, 18:52
Make a custom message handler as suggested by calhal.

qtUser500
18th November 2009, 14:01
Thank you both for the suggestions.
Appreciate it.:)