On this page

View CMake project contents

The Projects view visualizes the build system structure of the project as a tree and lists all files that are part of the project. Qt Creator automatically runs CMake to refresh project information in the view when you edit a CMakeLists.txt configuration file in a project. Also, refreshes project information when you build the project.

CMake project in Projects view

To disable this behavior, go to Preferences > CMake > General and clear Autorun CMake.

General tab in CMake preferences

Re-configure CMake projects

If Qt Creator cannot load the CMake project, the Projects view shows a <File System> project node to avoid scanning the file system and load the project faster. The node shows the same files as the File System view.

To re-configure the project:

  1. Go to Build, and select Clear CMake Configuration.
  2. Go to Build, and select Run CMake.

Hide subfolder names in Projects view

The Projects view shows the names of the subfolders where the source files are located. To hide the subfolder names and arrange the files only according to their source group, select Preferences > CMake > General, and then clear the Show subfolders inside source group folders check box. The change takes effect after you go to Build and select Run CMake.

Find header files not listed as sources

CMake does not need the header files of a target to be listed in add_executable() or add_library(), because the compiler reports them while it compiles the sources. Qt Creator lists the files that the project lists, so a header that is left out is missing from the Projects view, and the code model has to guess which include paths and preprocessor definitions apply to it.

To ask the compiler for the header files instead, go to Preferences > CMake > General, and select Find header files by asking the compiler.

Qt Creator then runs the compiler in dependency mode over the source files of the project and adds the header files that they include to the Projects view and to the code model. Only the header files inside the source directory and the build directory are added. The rest come from the compiler or from an installed package, and the include paths of the project already cover them.

The header files appear in the Header Files group of the target that compiles the source file which includes them. Because there is no entry for them in the CMake files, you cannot remove or rename them from the Projects view.

The first run scans the whole project, which takes a while on a large one, and shows its progress in the Progress bar. Qt Creator keeps the result in the build directory and afterwards only scans the source files whose header files changed.

Note: Header files that nothing includes stay hidden, as do the ones that only a build configuration other than the current one includes. Listing the header files in the CMake files is still the only way to show them all.

See also How to: Build with CMake, CMake, Open projects, File System, and Projects.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.