Adding files inside a Creator project

31,135

Solution 1

Use qmake - project from the command line in the directory containing the files and they will generate a .pro and you can copy that into a .pri and then include the .pri in your project, thus allowing you to access and edit the files from within Creator but segregating them nicely should you choose to use those files in other projects as well, but maintaining a single set of build and qmake settings.

Solution 2

Right Click on the project -> Add Existing Files... -> Choose your desired external headers this way you can edit them (but it is not recommended to edit external headers)

Note: This way, the files will get compiled with your project, so you need to include all dependencies.

Solution 3

If you add project headers to a target in CMakeLists.txt, they'll show up in Qt Creator.

file(GLOB HEADERS src/*.hpp src/*.h)
file(GLOB SOURCES src/*.cpp)
add_library(FreenectDriver SHARED ${HEADERS} ${SOURCES})

qtcreator-cmake

Share:
31,135
johnbakers
Author by

johnbakers

likes programming computers, but never studied it anywhere. asks a few good questions and a lot of dumb ones (i've actually learned more from the stupid questions). looks up to nearly all other programmers, regardless of their age.

Updated on August 10, 2022

Comments

  • johnbakers
    johnbakers almost 2 years

    I can add headers to the header path but how can I bring in external headers to be available within Creator for editing in project, so they appear in the file list like other headers created from scratch? in Xcode, you could just drag files into the project, they'd be copied into the project directory and appear in the IDE for editing. I'd assume you could do this in Creator but I can't find any way to do so.

  • johnbakers
    johnbakers over 10 years
    This option does not actually add the files to the creator project file list so you can work with him within the creator like you would other files
  • thuga
    thuga over 10 years
    @OpenLearner It should.
  • johnbakers
    johnbakers over 10 years
    @thuga I have discovered that you must use qmake -project to generate a file list that Creator will show.
  • Bret
    Bret over 8 years
    The add existing files option is grayed out for me ¯\_(ツ)_/¯
  • Thomas LAURENT
    Thomas LAURENT almost 8 years
    @Bret Qt Creator supports those file management functionalities for qmake projects only, if you use another compiler it'll be grayed out ;)
  • eric
    eric about 6 years
    So then how do you add files to a project for a cmake project?