Unsolved QtCreator : rename a source file from a CMake project
-
Hello,
It seems that source file renaming isn't supported by QtCreator for CMake projects (on my computer the context menu entry is grayed out).
Is it on the roadmap?
Is there any reason to have it unsupported today while QtCreator focuses more and more on CMake?
I see no ticket about it in the bug tracker. -
Hi @Kiruahxh,
you are fully right, the CMake support is underrated, compared to e.g. qmake.
There might be no ticket for renaming, but at least tickets for adding files to the CMake project do exist.
The last discussion I'm aware of is this one, and the outcome was, a support from CMake side is needed to implement the CMake project file editing.
I cannot tell if that is really the only possible solution, but I tend to agree that having support for project file handling would be nice.
Regards
-
For now, I only have a little project with GLOB. In my case, the menu entry "Add new" > "class" works fine.
With a manual list of sources, I don't know if it works well too. -
Don't use GLOB for source file 'search' for add_executable() or add_library() - it may not work well and will for sure not work when you simply add a new source file without running cmake afterwards.
-
Yeah I know it is not recommended. For a small project, it works fine ; and CONFIGURE_DEPENDS helps to detect new files.
Once the project grows we will for sure list the files.Still, Qt not supporting file renaming is bad news.
-
You can easily rename the source files that represent classes by right clicking on the class name in the header -> Refactor -> Rename Symbol Under Cursor. In the rename window at the bottom there is a "Rename 2 files" checkbox.
After you refactor, make sure you update the CMake and run CMake to refresh the code model. Sometimes the "Rename X files" options is not available if the code model is stale.
Nice productivity boost for me when I found this.
I do think it should be part of the context menu under the project view though. Potentially have "Refactor -> Rename Class" in the context menu in project view.