Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Add and edit existing source file to a project

Add and edit existing source file to a project

Scheduled Pinned Locked Moved Qt Creator and other tools
10 Posts 5 Posters 23.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qttester5
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      how you mean?
      in QtCreator's Side Bar choose File System instead of Projects and open any fs file ...

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qttester5
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NicuPopescu
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qttester5
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hmbright
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hmbright
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi and welcome to devnet,

                  Do you have the the sidebar visible ? If yes, do you have the Projects widget visible ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi and welcome to devnet,

                    Do you have the the sidebar visible ? If yes, do you have the Projects widget visible ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      ManuelMB
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved