正在安装消息处理程序
Installing message handler
我尝试通过使用qinstallMessageHandler()
函数安装消息处理程序来为应用程序创建日志文件。我的程序如下:
#include <QCoreApplication>
#include <QtDebug>
#include <QDir>
#include <fstream>
#include <iostream>
#include <QtCore>
#include <stdio.h>
#include <stdlib.h>
FILE *fd;
void myMessageOutput(QtMsgType type, const char *msg)
{
QString timeStamp = QTime::currentTime().toString("hh:mm:ss:zzz");
switch (type) {
case QtDebugMsg:
fprintf(fd, "[%s]", timeStamp.toStdString().c_str());
fprintf(fd, "[Debug] %sn", msg);
break;
case QtWarningMsg:
fprintf(fd, "[%s]", timeStamp.toStdString().c_str());
fprintf(fd, "[Warning] %sn", msg);
break;
case QtCriticalMsg:
fprintf(fd, "[%s]", timeStamp.toStdString().c_str());
fprintf(fd, "[Critical] %sn", msg);
break;
case QtFatalMsg:
fprintf(fd, "[%s]", timeStamp.toStdString().c_str());
fprintf(fd, "[Fatal] %sn", msg);
abort();
}
}
int main(int argc, char *argv[])
{
fd = fopen("log.txt", "a");
qInstallMessageHandler(myMessageOutput);
QCoreApplication a(argc, argv);
qDebug()<<"t Hello World!!! n";
return a.exec();
}
但是编译后我得到了以下错误:
错误:从"void()(QtMsgType,const char)"到"QtMessageHandler{aka void(*)(QtMsgType,常量QMessageLogContext&,常量QString&)}"的转换无效[-fpermission]
这里有谁以前也遇到过同样的问题?
看起来您切换到Qt5并使用了Qt4.x中定义的消息处理程序函数签名
void myMessageOutput(QtMsgType type,
const QMessageLogContext &context,
const QString &msg)
{
[..]
}
相反。
相关文章:
- 设计帮助 - 为不同类型的消息处理通用接口的设计模式
- 我的控制台处理程序不处理 CTRL+C,即使设置正确
- 处理程序在处理 SIGWINCH 后挂起
- 是否可以在QT GUI应用程序中处理事件时播放加载动画指示器?
- 程序在处理矢量时会接收`sigtrap'
- 为什么调用单例类 Qt 消息处理程序成员函数会出现错误:缺少参数列表
- MFC编辑控制消息处理访问文档对象
- 使用非静态消息处理程序获取GSTREAMER总线消息
- 无法获取程序来处理WM_PowerBroadcast消息
- MFC单选按钮组消息处理程序
- 在控制台应用程序中处理空的windows消息队列
- 主对话框在命令消息处理程序返回之前销毁
- 正在安装消息处理程序
- 如何在 wndproc 消息处理程序中在窗口下触发 jit 调试器
- 消息处理程序中的 RAND_event() 会导致 UI 中的小冻结吗?
- 使用消息处理程序将 c++ dll 调用转换为 delphi
- 如果对象将在消息处理程序中使用,如何解决内存泄漏问题
- 如果安装在单独的类上,Qt消息处理程序将崩溃
- 未能安装按钮消息处理程序
- 消息处理程序未调用窗口过程