Qt World Summit: Submit your Presentation

Not compiling files in project

  • One of my projects has lots of .cpp and .h files. Some of them are no longer needed but I want to keep them because they have useful methods and functions in them. Without removing them from the project, can I compile the project without them? What would I need to do to achieve this?

  • @BrianE

    Looks like a strange concept to me.

    A project is defined as a bunch of files you like or have to compile for creation of a library or an executable.
    When you do not want to put a compiled into a lib or exe, just remove them from the project file. You can leave them where they are, but they are no longer compiled and not linked to your lib/app.

    If you have just a couple of files, it does not really matter. When change quite a bit with large amounts of files, you might loose the overview soon. Therefore, it would be better to archive files somewhere save (e.g. use of git or somthing).

  • @BrianE
    I would have thought you could use https://forum.qt.io/topic/74990/exclude-source-from-build principle to achieve what you want?

  • Lifetime Qt Champion


    If you really want to keep them visible, you can put them under OTHER_FILES. Qt Creator will show them but they won't get built.

    However, as @koahnig suggest, it's better to remove dead code that's going to rot and have the in your VCS if you need them at some point.

  • Thanks Guys!

    I hadn't spotted the Remove File... menu entry and that does what I want. That leaves my files within the project directory but not in the project itself, which is what I wanted, ie to preserve the functions for their possible reuse in later projects but not this one any longer. One day I'll work out how to do Libraries in Qt - I used them when I was programming with Borland's Builder.

  • @BrianE

    No problem.

    Certainly the "Remove FIle" is an option. However, personally I prefer simply editing the project *.pro or its includes and do a rerun of qmake in Qt creator to make sure. The nice part there is also that you can use the "comment" key strokes and mark sections for temporary removal of files from a project.

Log in to reply