qtqt6qtcore

Why can I not include <QtLogging> with Qt6 Core?


According to doc.qt.io, functions like qInfo and qDebug require the inclusion of <QtLogging>. Unlike with most doc pages, there are no detailed instructions for CMake/qmake; I assume this header is part of Qt Core based on the category this page resides in.

However, my compiler fails to locate this specific header with a basic CMake setup. Is there something I'm missing as a beginner Qt user, or are the docs wrong?

Minimal reproducible example

# On Debian 12
apt install g++ cmake qt6-base-dev

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)

project(qtlogging_test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()

qt_add_executable(qtlogging_test main.cpp)

target_link_libraries(qtlogging_test PRIVATE Qt6::Core)

main.cpp:

#include <QObject> // Check for broken environment
#include <QtLogging>

int main() {
        (void) (qInfo());
        return 0;
}
$ cmake -B build && cmake --build build
-- The CXX compiler identification is GNU 12.2.0
[...]
-- Found Threads: TRUE  
[...]
-- Found WrapAtomic: TRUE  
[...]
-- Build files have been written to: /tmp/fj/build
[ 25%] Automatic MOC and UIC for target qtlogging_test
[ 25%] Built target qtlogging_test_autogen
[ 50%] Building CXX object CMakeFiles/qtlogging_test.dir/qtlogging_test_autogen/mocs_compilation.cpp.o
[ 75%] Building CXX object CMakeFiles/qtlogging_test.dir/main.cpp.o
/tmp/fj/main.cpp:2:10: fatal error: QtLogging: No such file or directory
    2 | #include <QtLogging>
      |          ^~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/qtlogging_test.dir/build.make:90: CMakeFiles/qtlogging_test.dir/main.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/qtlogging_test.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

Solution

  • This is a problem specific to official Debian 12 dpkg packages. <QtLogging> is a very recent addition introduced somewhere between Qt 6.4.2 and Qt 6.5, and Debian 12 ships Qt 6.4.2.