Programming/Qt

How to Resolve Warning Messages When Adding Header Files in Qt 6.8.1

변화의 물결1 2025. 4. 8. 00:04

 

 

Hello,

 

 I'd like to share how to resolve the persistent warning messages that appear when adding header files while using Qt 6.8.1.

 


1. Warning Message

 

Even when creating a basic Qt widget project, the following warning message appeared (with QMake configuration):

 

D:\project\02_qt\01_error_test01\widget.cpp:2:
warning: Included header ui_widget.h is not used directly (fix available)

 

 

 

 I thought it was a QMake characteristic, so I created the same project with CMake. Unlike the project created with QMake, the CMake project did not show warnings for the ui_widget.h file in the widget.cpp file.

 

 

 

 So, I thought it was a QMake issue. However, when I created and added a person class, the warning reappeared. Ultimately, it wasn't a QMake or CMake issue.

 

 The program runs without problems despite the warning message.

 

 

 

2. Solution (?)

 

 I searched the internet for ways to eliminate the warning message and tested them. I tried several methods, such as implementing the code directly in the header file or actually using the code, but none of them worked.

 

 Even after creating a person class in person.h and adding extern, code implementation, and function calls to the code, the warning message persisted in the person.h file.

 

 

 

 As a workaround, I found a way to disable the Clangd feature. Simply uncheck "Use clangd" in the "Edit > Preference > C++ > Clangd" menu.

 

 

 

 However, I realized that disabling Clangd also disables other warning messages. So, I looked for a way to suppress only the header file warning messages.

 

 Click the configuration link (here) at the bottom of "Edit > Preference > C++ > Clangd" (keep "Use clangd" checked).

 

 

 The config.yaml file appears in the editor, and it's configured as follows: Change "UnusedIncludes: Strict" to "None" and save.

 

 

 

 Now, you can see that the initial warning message for person.h has disappeared from the widget.cpp file.

 

 

 

 Clangd provides various alerts for optimization, but I haven't found the exact reason for this message yet.

 

 If anyone knows the correct solution other than the above method, please leave a comment.

 

 

Thank you.

 

 

<Reference Sites>

1. Qt Creator :: Included [file] is not used (fix available)

https://www.ovenproof-linux.com/2022/07/qt-creator-included-file-is-not-used.html

2. [clangd][include-cleaner] False warning: Included header X is not used directly

https://github.com/llvm/llvm-project/issues/75777

3. clangd Configuration

https://clangd.llvm.org/config  

반응형