How can I remove files from a QtCreator project

14,610

Solution 1

If your project is generated from CMake, the file list is determined by the CMakeLists.txt file, and you cannot add or remove files manually from the source tree in QtCreator. Especially if your CMakeLists file specifies the glob operator for a project's file list, you must manually remove the files from disk and re-run CMake from within QtCreator by going to Build->Run CMake (QtCreator 3.3.0). This will update the file list but also regenerate the project (cbp) file - re-running CMake outside of QtCreator will not update the project file and you will have ghost entries of deleted files showing up in the source tree if you deleted them from disk.

Solution 2

Right-click the file you want to remove, and choose "Remove File..."

Checking the "Delete file permanently" check box will delete the file, otherwise it will just be removed from the project.

Share:
14,610
Admin
Author by

Admin

Updated on October 16, 2022

Comments

  • Admin
    Admin over 1 year

    Might be a very newbie question, but I can't find a way to remove files from my projects in QtCreator. Thanks!

  • Dennis
    Dennis about 14 years
    Ah didn't find it either, you have to delete the files and not the folders.
  • lawlove
    lawlove about 10 years
    That apparently just temporarily removes the project from the startup page - at least for the CMakeLists.txt case. The CMakeCache.txt also had entries for the project name but even after deleting those, it re-created the project name so it reappeared on the start page
  • lawlove
    lawlove about 10 years
    Ahh - because that's the project name in CMakeLists.txt ; so any time I selected CMakeLists.txt to create a new project it gives it that name.
  • Daniel Saner
    Daniel Saner over 9 years
    Thanks! Deleting the build directory is definitely necessary when using MSVC2010. I was wondering why it was still looking for files no longer mentioned anywhere in the project.
  • Harvey
    Harvey over 9 years
    This is not what the original post was asking for. (But it was what I was looking for - thanks.)
  • Andy
    Andy about 9 years
    And if "Remove File..." is disabled?
  • Markus Meskanen
    Markus Meskanen almost 8 years
    The question is, why doesn't Qt creator do this automatically?
  • flatline
    flatline almost 8 years
    I'm pretty sure I don't want Qt creator changing my cmake code behind the scenes, so deleting the file from the filesystem is at best going to be a half-measure that doesn't really achieve the objective. Some notification to this effect would be helpful though.
  • Josh
    Josh about 7 years
    Be warned that this option still deletes files (at least on Windows) even if you have the box unchecked. It's not in my recycle bin either.
  • vlz
    vlz over 4 years
    The Remove File... option might be disabled, because the file is from a different project AND that project is not ocrrectly configured. In that case it should be contained in a project folder higher up in the tree. You can right-click that folder and choose Close project "project name".
  • Joules
    Joules about 2 years
    had this issue, doing it manually fixed my project tree