Add and edit existing source file to a project
-
wrote on 9 Oct 2013, 05:46 last edited by
Is it possible add (copy) an existing source file to a Qt Creator project and have it appear in the project file list inside Creator so you can edit it? I only see options (via Add Existing Files) for adjusting the info in the .pro file, but the files themselves, even if previously placed inside the project directory, will never appear in Creator and thus cannot be edited inside Creator.
-
wrote on 9 Oct 2013, 16:20 last edited by
how you mean?
in QtCreator's Side Bar choose File System instead of Projects and open any fs file ... -
wrote on 10 Oct 2013, 00:24 last edited by
I want to know how to add a file to the project hierarchy file list (headers, sources in separate project directories in the file list of Creator). When using the Add Existing Files, all it does is add paths to the .pro, and there is no way I can find to actually bring in outside files that you want to become part of the project directly. Except of course creating a new .pri as a separate project and including that instead.
-
wrote on 10 Oct 2013, 12:13 last edited by
I don't know exactly what you need, but:
- for headers you can define paths for searching with INCLUDEPATH
- for source files you can either define paths with wild characters
i.e.
SOURCES += src/*.cpp
or define variables like SRC_PATH = src dir path and use with $$SRC_PATH
why you should be "free" to add sources from outside .pro file while you should be very careful where to add them for build flow? I mean for instance when you build upon other project source dir and have duplicated header names you have to handle which is searched first for a compilation unit
Cheers!
-
wrote on 10 Oct 2013, 12:18 last edited by
I guess my point is that sometimes you are refactoring code from another system and you want to bring in existing source files into a project and edit them as part of the project, not just link to them and use them but actually have them be raw source that belongs to the project. And Qt Creator doesn't really support this from everything I can tell, unless you use qmake to build a new .pro from scratch... but once it is built, you cannot add anything else to the Creator hierarchy without doing this all over again.
-
wrote on 8 Feb 2015, 04:44 last edited by
i had a strange experience trying to figure out how to add a single .cpp file to my project in the proper "qt-creator 3.3" way (current as of feb 2015). most of the web searches relate to old qt-creator that no longer exists ('right click in the tree in the project window' - there is no tree, there is no project window). this is the thread that seems to describe what is really going on -
Qt Creator doesn't want you to add .cpp files.
But it's rather common in the 'open source world' to do that kind of thing.
I searched in vain for 'add file to project' commands. There are none. I found 'open file'. . . it doesnt add it to the project.
I tried to edit the .pro file in the new qt creator... 3.3, . . it wont let you. if you try to open a .pro file it says "error, project already open". If you close your project, then open the .pro file, it doesnt open the .pro file, it doesnt open any file. the editor window is completely blank.
The only way it appears you can add a .h or .cpp file to a qt-creator project is to Not Use qt-creator. Instead, use qmake -project, as mentioned.... or.... edit the .pro file in some other editing program, add the source files by hand under SOURCES, and then go back and re-start qt-creator.
-
wrote on 8 Feb 2015, 04:44 last edited by
i had a strange experience trying to figure out how to add a single .cpp file to my project in the proper "qt-creator 3.3" way (current as of feb 2015). most of the web searches relate to old qt-creator that no longer exists ('right click in the tree in the project window' - there is no tree, there is no project window). this is the thread that seems to describe what is really going on -
Qt Creator doesn't want you to add .cpp files.
But it's rather common in the 'open source world' to do that kind of thing.
I searched in vain for 'add file to project' commands. There are none. I found 'open file'. . . it doesnt add it to the project.
I tried to edit the .pro file in the new qt creator... 3.3, . . it wont let you. if you try to open a .pro file it says "error, project already open". If you close your project, then open the .pro file, it doesnt open the .pro file, it doesnt open any file. the editor window is completely blank.
The only way it appears you can add a .h or .cpp file to a qt-creator project is to Not Use qt-creator. Instead, use qmake -project, as mentioned.... or.... edit the .pro file in some other editing program, add the source files by hand under SOURCES, and then go back and re-start qt-creator.
-
Hi and welcome to devnet,
Do you have the the sidebar visible ? If yes, do you have the Projects widget visible ?
-
Hi and welcome to devnet,
Do you have the the sidebar visible ? If yes, do you have the Projects widget visible ?
-
wrote on 11 Sept 2022, 09:33 last edited by
You can do this by switching from the project view to the file system view in the side bar then you can right click and hit new to create a new file.