bug信息输出到制定文件中,方便找出问题所在!
#include <QApplication>
#include <QTextCodec>
#include <QTime>
#include <QFile>
#include <qapplication.h>
#include <stdio.h>
#include <stdlib.h>
#include <QApplication>
#include <QDebug>
#include <QTextCodec>
#include <QIcon>
#include <QObject>
#include "mainwindow.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QTime current_time = QTime::currentTime();
QString txt;
switch (type)
{
//调试信息提示
case QtDebugMsg:
txt = QString("Debug: %1").arg(msg);
break;
//一般的warning提示
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();
}
txt = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd") +QString(":%1").arg(current_time.msec()) + txt;
QFile outFile("debuglog.txt");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char *argv[])
{
QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
qInstallMessageHandler(myMessageOutput);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}