Menu

Cppcheck reports missingIncludeSystem on Qt headers

2023-11-08
2023-11-08
  • therisktaker

    therisktaker - 2023-11-08

    Hi,
    I created basic QtWidgets project on Qt 5.15.2. File structure:

    .
    ├── CMakeLists.txt
    ├── main.cpp
    ├── mainwindow.cpp
    ├── mainwindow.h
    └── mainwindow.ui
    

    In CMakeLists.txt I added Cppcheck run target (see below for used options):

    add_custom_target(cppcheck-check COMMAND ${CPPCHECK}
        --check-level=exhaustive
        --cppcheck-build-dir=${CMAKE_BINARY_DIR}
        --enable=all
        --error-exitcode=1
        --inline-suppr
        --language=c++
        --platform=native
        --project=${CMAKE_BINARY_DIR}/compile_commands.json
        --library=qt
        -i ${CMAKE_BINARY_DIR}
        -j ${N_PROC}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        USES_TERMINAL
    )
    

    and provided there for example --libarary=qt option. But Cppcheck still reports missingIncludeSystem issues on Qt headers like:

    Checking /home/user/sandbox/CppcheckTest/main.cpp ...
    /home/user/sandbox/CppcheckTest/mainwindow.h:4:0: information: Include file: <QMainWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    #include <QMainWindow>
    ^
    /home/user/sandbox/CppcheckTest/main.cpp:2:0: information: Include file: <QApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    #include <QApplication>
    
    ...
    

    Question is: how can I suppress these warnings without using --suppress=missingIncludeSystem? What am I missing?

    Project files in attachments. To setup, build and run analysis (assuming you install Qt from Qt Online Installer and using Ninja) run from project root in terminal below commands, change user to yours or provide own path:

    cmake -S . -B build -G Ninja  -DCMAKE_PREFIX_PATH=/home/<user>/Qt/5.15.2/gcc_64
    ninja -C build
    ninja -C build cppcheck-check
    

    Tested on Ubuntu 22.04, Qt 5.15.2 and Cppcheck 2.12.1.

     
  • CHR

    CHR - 2023-11-08

    This is by design. Any missing header included by <...> is reported as missingIncludeSystem.

     
    👍
    1
    • Daniel Marjamäki

      It is by design.. but well I can understand that it is confusing.

      We recommend that you use the --library=qt option when checking qt code. However this does not prevent missingIncludeSystem warnings.

      Please ignore the missingIncludeSystem warnings about qt.

       
      👍
      1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.