When running my Qt5 application on linux, I don't see any output from qDebug, qWarning, qCritical or qFatal. I know that I can use qInstallMsgHandler
to install a message handler and see them, but this is rather heavyweight.
I just want to check the qWarning log to see if there is any signal that mis-connected. Is there a way to look at this log? A special command-line option, an environment variable?
I think I remember that in the past, everything was printed to stderr, perhaps that's a Qt5 change?
If you are using visual studio, qDebug etc are printed to the output window in the IDE.
If you happen to run Arch Linux, which compiles Qt with the
-journald
option, all debug output is per default directed to the systemd journal (display withjournalctl
).You can override this behaviour by defining
QT_LOGGING_TO_CONSOLE=1
as an environment variable.They are still printed to standard error.
If you launch the application from the command line, it is usually printed there, or if using Qt Creator, it's displayed in the Application Output window.
Please do not make the mistake of assuming that qDebug, qWarning, qCritical and qFatal always log on standard error. That's absolutely not the case.
The actual destination varies depending on the Qt configuration and the targeting OS. Plus, 5.4 introduced some behavioural changes. See here and here for discussions.
TL;DR:
On Qt >= 5.4:
QT_LOGGING_TO_CONSOLE
environment variable to1
.QT_LOGGING_TO_CONSOLE
environment variable to0
(this will force logging through the native system logger).QT_LOGGING_TO_CONSOLE
environment variable is not set, then whether logging to the console or not depends on whether the application is running in a TTY (on UNIX) or whether there's a console window (on Windows).On Qt < 5.4, the situation is more confusing.
The problem with the pre-5.4 approach was that, f.i., under Unix IDEs would not capture an application's debug output if Qt had been built with journald support. That's because the output went to journald, not to the IDE. In 5.4 the approach has been made more flexible and uniform across OSes.