No qDebug()<<"Output"; on android
-
...........
Update: this problem might very well be linked to that pointed out here: https://forum.qt.io/topic/157825/waiting-for-the-debugger-to-attach
...........
Writing for Android I don't see any qDebug()<<"Output"; whatsoever. Only after I've ended the program (e.g. from the phone by its back button), I see:15:05:59: "org.qtproject.example.myTestProject" died.
The problem occurs in new projects and across different Qt Versions.
.........
Update: It does, although, not appear on another person's Android device (Samsung Tablet SM-T830 with Android 10).
.........
I don't see anything in "Application Output" pane (except the above, after program ends).Debug output when running on Windows is fine, however. There everything works like expected.
The code I use is simply:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QDebug> int main(int argc, char *argv[]) { // [automatically generated QML stuff omitted here] engine.load(url); for (int i=0; i<100;i++) qDebug()<<"###############################!!!!!!!!!!!!!###############"; // for (int i=0; i<100;i++) std::printf("###############################!!!!!!!!!!!!!###############"); return app.exec(); }
I've tried:
- making sure I use DEBUG configuration^^
- restarting Windows machine and phone
- adding android:debuggable="true" to <application...> tag in AndroidManifext.xml
- toggling Edit|Preferences|Debugger|General|Force Logging To Console
- toggling Edit|Preferences|Build&Run|Application Output|Merge stderr and stdout
- starting new projects in different Qt Versions: 5.15.2, 6.5.1 and 6.7.2, with compat option(qmake) and without(cmake)
- using std::fprintf(stderr, "output");
- using std::cerr << QString("Output").toStdString() << std::endl;
- setting qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");
- uninstalling app before deploying again
- removing build folders
In the the (otherwise very vivid and cluttered) adb logcat the output does appear as
07-20 14:26:46.551 17346 17367 D libtestLogCompat_arm64-v8a.so: ###############################!!!!!!!!!!!!!############### 07-20 14:26:46.552 17346 17367 I chatty : uid=10169(org.qtproject.example.testLogCompat) qtMainLoopThrea identical 98 lines 07-20 14:26:46.552 17346 17367 D libtestLogCompat_arm64-v8a.so: ###############################!!!!!!!!!!!!!###############
Would be fine - but it's buried under thousands of other log lines.
The same applies for console.log("output") from QML
N.B.: I couldn't find output to std::printf anywhere.Win 10 machine, Qt Creator 13.0.2, deploying to a Nokia 8 (TA-1012) with Android 9, several Qt versions.
-
-
-
I don't understand why but qWarning() works OK ;)
other solution, use spdlog
#include "spdlog/sinks/android_sink.h" // auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true); // file_sink->set_level(spdlog::level::trace); auto android_sink = std::make_shared<spdlog::sinks::android_sink_mt>("ssss", false); android_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); // to dziala jak jest "false" powyżej spdlog::set_default_logger(std::make_shared<spdlog::logger>("multi_sink", spdlog::sinks_init_list({android_sink // ,file_sink })) ); spdlog::info("###############################!!!!!!!!!!!!!###############");