Hi,
How to redirect the qDebug() output to a file instead of application output
Regards,
Srikanth
Hi,
How to redirect the qDebug() output to a file instead of application output
Regards,
Srikanth
Simplest way without changing code:
your_excutable > your_file
or
your_excutable >& your_file
Hi,
Thank you for your reply but I would be installing the application on the device, is there any other way please suggest
-Srikanth
Hi,
Install a message handler using "qIntallMsgHandler" and there you can use "QTextStream" to write the message to a file.
Also, think that "qDebug" only will work when the application is compiled as debug.
Òscar Llarch i Galán
try this
Qt Code:
#include <QApplication> #include <QtDebug> #include <QFile> #include <QTextStream> void myMessageHandler(QtMsgType type, const char *msg) { QString txt; switch (type) { case QtDebugMsg: break; case QtWarningMsg: break; case QtCriticalMsg: break; case QtFatalMsg: abort(); } ts << txt << endl; } int main( int argc, char * argv[] ) { qInstallMsgHandler(myMessageHandler); ... return app.exec(); }To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
GuusDavidson (6th July 2011), monst (28th April 2012)
Thanks a lot for your suggestions I appreciate it
Also it is recommended to "handle" fatal messages (using abort() or exit(-1) or something akin) because that's what the default handler does and if you don't do it you're likely to end up with segfaults instead (though not necessarily at the same place so you may have a hard time tracking the bugs...).
Current Qt projects : QCodeEdit, RotiDeCode
Qt Code:
... case QtFatalMsg: abort(); ...To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Qt is using that handler in the function qt_message_output() and then it's checking if the message is QtFatalMsg and generating core dump or sth, so there is no need to implement it in addition to that. Whats more it's more complicated on Windows (with msvc) than just abort() in default implementation.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Bookmarks