标签:style io ar color os 使用 sp for on
#include<QDebug>
int main(int argc, char *argv[])
{
qDebug()<<"hello qDebug";
qWarning()<<"hello qWarning";
qCritical()<<"hello qCritical";
// qFatal() <<"hello qFatal"; //can use like this
qFatal("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 start
qInstallMsgHandler(customMessageHandler);
...
return app.exec();
}
#ifndef QT_NO_DEBUG_STREAM
QDebug 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
标签:style io ar color os 使用 sp for on
原文地址:http://blog.csdn.net/godvmxi/article/details/41774815