Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Problem with source files in multiple directories

[SOLVED] Problem with source files in multiple directories

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 8.4k 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.
  • N Offline
    N Offline
    notgary
    wrote on last edited by
    #1

    I'm currently writing my Qt app and am storing the interface source files in a subdirectory of the root directory called 'ui', so that @main.cpp@ which is kept in the root directory, uses the line @#include ui/mainwindow.h@ to import the main window. I've already compiled and ran this app with the files all sitting in the one directory and there were no problems then, but now after I've split them up qmake tells me it can't find them when I try to make the @.pro@ project file. Is there anything special that I'm supposed to do to get qmake to recognise source files in child directories?

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Did you use the ui subdirectory in you pro file?
      Eg. :
      Headers += ..../ui/mainwindow.h

      Also do the same with other files like sources

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • N Offline
        N Offline
        notgary
        wrote on last edited by
        #3

        Wouldn't that be wiped out each time I build the project? Isn't there a way have qmake pick it up the same way it found the headers the first time round?

        1 Reply Last reply
        0
        • H Offline
          H Offline
          HuXiKa
          wrote on last edited by
          #4

          @INCLUDEPATH += ui@ maybe?

          If you can find faults of spelling in the text above, you can keep them.

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            No @qmake@ looks in your pro file

            Once you have a pro file you don't want it to be generated automatically. Suppose you need a library in another path and you added it manually...

            I suppose you used @qmake -project@ the first time? Like this you let qmake autogenerate its contents.

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • N Offline
              N Offline
              notgary
              wrote on last edited by
              #6

              Thanks a lot for your help. That's done the trick. I didn't realise you only generated the @.pro@ file once.

              1 Reply Last reply
              0
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                So...I'm working on a project that's getting bigger than I originally thought, and I'd like to retroactively introduce a directory structure to my source and header file organization. I notice that Creator doesn't have an "add directory" option.

                Should I just add the directories in the file system, start moving files around, and run qmake again? Any "gotchas" that I should be aware of?

                Thanks.

                1 Reply Last reply
                0
                • AlicemirrorA Offline
                  AlicemirrorA Offline
                  Alicemirror
                  wrote on last edited by
                  #8

                  @mzimmers: it is true, Creator has nothing to do with file management. I think that the right perspective you should see it is as a manager for the project with all the related stuff.
                  The file management should be left to the file manager / file system tools and applications. When you need to split or add new folders you will do it externally. Then instead searching something like adding new files etc. there is the command "add existing file" As you use it you can add almost anything you need in your project from inside the project folder or outside it.

                  I think that the best practice (maybe ???) procedure will be :

                  Add the files in the folders where you need

                  Go in the project tree from the Creator and right click with the mouse selecting add existing ifle

                  Explore your folder tree and add the files you need from the desired folders (also outside the project folder tree)

                  If these are resouces (i.e. images or QML documents) and you are using environments like Harmattan you should add these files in the project resource file too.

                  If these files need a .pro file update edit the project file as suggested by Eddy above.

                  Two notes:

                  • If these operations should be done with a project managed too with a git or svn versioning system when you remove files from a project or move them remember to do the same with the repository to avoid problems in the further commits: not all the repository operations are managed by Creator.
                  • In versions previous Qt 4.7.3 the command add existing files can be found right-clicking only the root of the project in the project explorer. Starting from the last versions of Qt-Creator included in Qt 4.73 this command appears in the contextual menu in all the folders.

                  Hope it can help.

                  Enrico Miglino (aka Alicemirror)
                  Balearic Dynamics
                  Islas Baleares, Ibiza (Spain)
                  www.balearicdynamics.com

                  1 Reply Last reply
                  0
                  • mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #9

                    Thanks, Enrico. I just experimented with one pair of files, and it seems to work OK.

                    By the way, your last point seems to be in error: I can perform the "add existing files" command by right-clicking on directories under the root. But, this is a minor point.

                    Thanks again.

                    1 Reply Last reply
                    0
                    • AlicemirrorA Offline
                      AlicemirrorA Offline
                      Alicemirror
                      wrote on last edited by
                      #10

                      Happy to hear that is works.
                      Rgarding the question that the command work anywhere, it is possible that I don't remember in what case it doesn't work. But it doesn't matter, it was just a reminder that the command exist also if in some conditions it does not appear.

                      Note that regadless where the file are they are put in sources, headers, other files etc. depending by the kind of file your are adding to the project.

                      Cheers.

                      Enrico Miglino (aka Alicemirror)
                      Balearic Dynamics
                      Islas Baleares, Ibiza (Spain)
                      www.balearicdynamics.com

                      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