brainplot
brainplot

Reputation: 141

Clion won't index auto-generated ui header files

I was having a look at the KeepassXC's source code, with Clion as my IDE of choice. After a bit of digging and navigating through the source code, I noticed that one of the source file has the following #include directive:

#include "ui_MainWindow.h"

with a red underline. Hovering over it with my mouse, it says "'ui_MainWindow.h' not found".

The project's CMakeLists.txt file provides three build types:

and, once all three build types are successfully built, the file CLion should look for is in the following location:

cmake-build-(debug|release|relwithdebuginfo)
└── src
    └── keepassx_core_autogen
        └── include
            ├── moc_KMessageWidget.cpp
            ├── ui_AboutDialog.h
            ├── ui_CategoryListWidget.h
            ├── ui_ChangeMasterKeyWidget.h
            ├── ui_CloneDialog.h
            ├── ui_CsvImportWidget.h
            ├── ui_DatabaseOpenWidget.h
            ├── ui_DatabaseSettingsWidgetEncryption.h
            ├── ui_DatabaseSettingsWidgetGeneral.h
            ├── ui_DatabaseSettingsWidget.h
            ├── ui_DetailsWidget.h
            ├── ui_EditEntryWidgetAdvanced.h
            ├── ui_EditEntryWidgetAutoType.h
            ├── ui_EditEntryWidgetHistory.h
            ├── ui_EditEntryWidgetMain.h
            ├── ui_EditEntryWidgetSSHAgent.h
            ├── ui_EditGroupWidgetMain.h
            ├── ui_EditWidget.h
            ├── ui_EditWidgetIcons.h
            ├── ui_EditWidgetProperties.h
            ├── ui_EntryAttachmentsWidget.h
            ├── ui_MainWindow.h
            ├── ui_PasswordGeneratorWidget.h
            ├── ui_SearchWidget.h
            ├── ui_SettingsWidgetGeneral.h
            ├── ui_SettingsWidgetSecurity.h
            ├── ui_SetupTotpDialog.h
            ├── ui_TotpDialog.h
            └── ui_WelcomeWidget.h

After a couple hours trying to make it work, I've noticed something weird. The red underline will go away (and the code navigation will work too) only if I build the project in Debug mode (i.e. it'll only pick the file from the cmake-build-debug). If I clean the debug build and use the release build, there's no way I can get CLion to pick the file from cmake-build-release. Same applies for cmake-build-relwithdebinfo.

The code compiles and runs just fine, meaning that the CMake configuration is correct.

Upvotes: 3

Views: 1780

Answers (3)

mhy
mhy

Reputation: 11

Just manually reload cmake project after build. It works fine for me.

Reference: https://youtrack.jetbrains.com/issue/CPP-22534

Upvotes: 1

hsusanoo
hsusanoo

Reputation: 914

You can solve this problem by changing Clion environment under Build, Execution, Deployment > Toolchains to use compilers installed with Qt instead. For MinGW 64bit you'll find it under C:\Qt\Qt5.x.x\Tools\mingwxxx_64.

Upvotes: 2

Jayen
Jayen

Reputation: 6069

this answer https://stackoverflow.com/a/31293158/192798 helped me find the solution for my case. i also had the same issue for you where it used to work and then suddenly couldn't find the header file. for me, i used target_include_directories so i had to tell clion to choose the configuration corresponding to the target. (i was choosing one of the target's dependents.) then i build, then i can switch to any configuration.

for your case, after switching the configuration, you may need to build to get clion to pick up the file.

Upvotes: 1

Related Questions