|
|
独立的小狗 · Android之startForegroun ...· 3 年前 · |
|
|
跑龙套的凉茶 · error TS2339: ...· 3 年前 · |
|
|
帅气的蚂蚁 · NOJ-西北工业大学Python编程作业61 ...· 3 年前 · |
我是 而不是 的QtCreator用户。我用qmake、make和androiddeployqt在构建脚本中构建android应用程序,并通过亚行安装将它们部署到设备上。
我希望能够在abd logcat输出中看到qDebug、qInfo等的输出,以及来自qml引擎的任何QML conole.log输出和任何其他聊天。但是在Android的Qt应用程序的一个普通版本中,任何这样的信息似乎都被屏蔽了(或者至少我不知道它们会去哪里)。
我已经取得了一些成功的结合:
但这一切似乎有点笨重,而且过于复杂。肯定有更好更简单的方法吗?(例如,在Windows上使用Qt,您可以使用
CONFIG += console
构建一个显示日志记录的控制台窗口,但该选项是特定于Windows的)。
Qt版本从5.7开始引起人们的兴趣。
在谷歌搜索这个输出重定向问题时,经常提到
adb shell setprop log.redirect-stdio true
,但据我所知,它对Qt应用程序的stout/stderr没有任何影响。
发布于 2017-08-02 11:49:21
实际上,将问题中关联的两种解决方案的各个方面结合起来,至少可以将其简化为一种功能:
const char*const applicationName="myapp";
#ifdef ANDROIDQUIRKS // Set in my myapp.pro file for android builds
#include <android/log.h>
void myMessageHandler(
QtMsgType type,
const QMessageLogContext& context,
const QString& msg
QString report=msg;
if (context.file && !QString(context.file).isEmpty()) {
report+=" in file ";
report+=QString(context.file);
report+=" line ";
report+=QString::number(context.line);
if (context.function && !QString(context.function).isEmpty()) {
report+=+" function ";
report+=QString(context.function);
const char*const local=report.toLocal8Bit().constData();
switch (type) {
case QtDebugMsg:
__android_log_write(ANDROID_LOG_DEBUG,applicationName,local);
break;
case QtInfoMsg:
__android_log_write(ANDROID_LOG_INFO,applicationName,local);
break;
case QtWarningMsg:
__android_log_write(ANDROID_LOG_WARN,applicationName,local);
break;
case QtCriticalMsg:
__android_log_write(ANDROID_LOG_ERROR,applicationName,local);
break;
case QtFatalMsg:
default:
__android_log_write(ANDROID_LOG_FATAL,applicationName,local);
abort();
#endif
int main(int argc,char* argv[]) {