Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Help OF with (adding ) "include" path ....

Help OF with (adding ) "include" path ....

Scheduled Pinned Locked Moved Unsolved C++ Gurus
when
4 Posts 3 Posters 766 Views 3 Watching
  • 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Could somebody nice tell me HOW TO ADD #INCLUDE WHEN IT IS not IN SAME pew / directory?

    Here is an example - I need to add #include to class file in project TEST_MAIN and add a path to get to the project btscanner.

    I know how to use "..." but I have NEVER fully understood how it works. So I am asking for advise how to ADD path to "include" . preferably using intelisense. ( Let the intelisense guide me... ) or just drag the path - from where...

    I sort of understand how it works, but looking for easy way to implement / add the path.

    785b8fea-f57a-4ae9-bdf9-bf04fa64940d-image.png

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      Do it in your pro file:

      INCLUDEPATH += ../somedir
      

      Then in cpp/h file:

      #include "file.h"
      

      C++ is a perfectly valid school of magic.

      A 1 Reply Last reply
      1
      • fcarneyF fcarney

        Do it in your pro file:

        INCLUDEPATH += ../somedir
        

        Then in cpp/h file:

        #include "file.h"
        
        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @fcarney Good idea , but
        it really does not answer my inquiry about the usage of ".../" - got a good reply in another forum...
        would be OK if I needed multiple access to same path - do not need that feature
        would defeat the philosophy to keep related stuff physically together
        Thanks
        Cheers

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          .. is just a part of a path meaning "one folder up". So you build your path just as you would "click it" in file explorer.
          Lets say you have a file structure like this:

          top
             project1
                something
                   header.h
             project2
                something
                   file.cpp
          

          and you want to include header1 in file.cpp. When starting from file.cpp location in a file explorer you would go two directories up and then two directories down to header.h.

          It's the same when constructing an include path. You start where the file you are in is. You go up twice and then down twice to the header, so:

          #include "../../project1/something/header.h"
          

          start in top/project2/something/ because that's where file.cpp is
          first .. takes you one up to top/project2/
          second .. takes you up to top/
          and then project1/something/ takes you to the header.

          But as @fcarney said that's not a good idea because you're hardcoding in your source a path to another project. That's not something you should do. What you should do is add a base path to the other project to your INCLUDEPATH variable and then you can make includes relative to that. So in the above example you would add path to project1 in project2 like this: INCLUDEPATH += ../project1 and then you could make a clean include like this in your file.cpp: #include "something/header.h".

          1 Reply Last reply
          1

          • Login

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