#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QTextStream>
// 自定义消息处理函数
void myMessageHandler(QtMsgType type, const char* msg)
{
// 打开输出文件
QFile file("debug.log");
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
QTextStream stream(&file);
// 设置消息格式
QString message;
switch (type) {
case QtDebugMsg:
message = QString("[Debug] ");
break;
case QtWarningMsg:
message = QString("[Warning] ");
break;
case QtCriticalMsg:
message = QString("[Critical] ");
break;
case QtFatalMsg:
message = QString("[Fatal] ");
break;
default:
break;
}
// 输出消息到文件
stream << message << msg << endl;
// 关闭文件
file.close();
}
}
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
// 设置自定义消息处理函数
qInstallMsgHandler(myMessageHandler);
// 示例使用QDebug输出
qDebug() << "This is a debug message.";
qWarning() << "This is a warning message.";
qCritical() << "This is a critical message.";
return app.exec();
}
/home/tronlong/workSpace/POCT-plugin/poct/poctclient.cpp:70: error: 'qInstallMessageHandler' was not declared in this scope
qInstallMsgHandler