Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android上定制Qt消息处理程序_Android_Qt_Debugging - Fatal编程技术网

如何在Android上定制Qt消息处理程序

如何在Android上定制Qt消息处理程序,android,qt,debugging,Android,Qt,Debugging,我正在使用qSetMessagePattern()自定义Qt应用程序的日志格式。在Windows上,qDebug()输出的正是我所期望的,但在Android上它以前添加了一些信息。 比如说 qSetMessagePattern("[D] %{message}"); qDebug("Debug test"); Windows输出: [D] Debug test Android输出: D/Qt (30070): ..\project\filename.cpp:521 (void Class::

我正在使用
qSetMessagePattern()
自定义Qt应用程序的日志格式。在Windows上,
qDebug()
输出的正是我所期望的,但在Android上它以前添加了一些信息。 比如说

qSetMessagePattern("[D] %{message}");
qDebug("Debug test");
Windows输出:

[D] Debug test
Android输出:

D/Qt  (30070): ..\project\filename.cpp:521 (void Class::method()): [D] Debug test
我尝试过创建一个自定义处理程序(并使用
qInstallMessageHandler()
安装它),但我不知道消息处理程序应该如何在Android上输出调试信息


问题:如何使Android消息处理程序停止预写该信息,或者如何为Android编写自定义消息处理程序。

找到了Android默认消息处理程序的代码,并且格式是硬编码的,因此我编写了一个类似的版本:

#include <android/log.h>

static void android_message_handler(QtMsgType type,
                                  const QMessageLogContext &context,
                                  const QString &message)
{
    android_LogPriority priority = ANDROID_LOG_DEBUG;
    switch (type) {
    case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break;
    case QtWarningMsg: priority = ANDROID_LOG_WARN; break;
    case QtCriticalMsg: priority = ANDROID_LOG_ERROR; break;
    case QtFatalMsg: priority = ANDROID_LOG_FATAL; break;
    };

    __android_log_print(priority, "Qt", "%s", qPrintable(message));
}
qInstallMessageHandler(android_message_handler);