#include<QDebug>int main(int argc, char *argv[]){qDebug()<<"hello qDebug";qWarning()<<"hello qWarning";qCritical()<<"hello qCritical";// qFatal() <<"hello qFatal"; //can use like thisqFatal("hello qFatal"); // will exit the program}
#include <QtDebug>#include <QFile>#include <QTextStream>void customMessageHandler(QtMsgType type, const char *msg){QString txt;switch (type) {case QtDebugMsg:txt = QString("Debug: %1").arg(msg);break;case QtWarningMsg:txt = QString("Warning: %1").arg(msg);break;case QtCriticalMsg:txt = QString("Critical: %1").arg(msg);break;case QtFatalMsg:txt = QString("Fatal: %1").arg(msg);abort();}QFile outFile("debuglog.txt");outFile.open(QIODevice::WriteOnly | QIODevice::Append);QTextStream ts(&outFile);ts << txt << endl;}int main( int argc, char * argv[] ){QApplication app( argc, argv );//Lets register our custom handler, before we startqInstallMsgHandler(customMessageHandler);...return app.exec();}
#ifndef QT_NO_DEBUG_STREAMQDebug debug() const;QDebug debug(const QLoggingCategory &cat) const;QDebug debug(CategoryFunction catFunc) const;QDebug warning() const;QDebug warning(const QLoggingCategory &cat) const;QDebug warning(CategoryFunction catFunc) const;QDebug critical() const;QDebug critical(const QLoggingCategory &cat) const;QDebug critical(CategoryFunction catFunc) const;QNoDebug noDebug() const Q_DECL_NOTHROW;#endif // QT_NO_DEBUG_STREAM
原文:http://blog.csdn.net/godvmxi/article/details/41774815