Unsolved [QTCreator] Open include from source directory, not build directory
-
I'm using QtCreator with a C++ project in which a separate build directory exists (using waf build system).
Waf copies all headers in a subdirectory in that build directory, such that the original hierarchy is of no meaning when including a header in a source file.Now when I follow an include obviously the header file from the build directory is opened. Can I somehow achieve that automatically the corresponding original file from the source directory is opened? When I switch header/source QtCreator opens the correct source file.
If there is no existing way, can this be done via some plugin API or so?
Best
-
@bandan said in [QTCreator] Open include from source directory, not build directory:
Waf copies all headers in a subdirectory in that build directory, such that the original hierarchy is of no meaning when including a header in a source file.
Now when I follow an include obviously the header file from the build directory is opened. Can I somehow achieve that automatically the corresponding original file from the source directory is opened? When I switch header/source QtCreator opens the correct source file.
Hi @bandan,
I'm not familiar with the Waf build system.
- Can you please show what your folder hierarchy looks like? (i.e. how the source and build directories relate to each other)
- How do you open your project from Qt Creator? Is it a .pro file, a CMakeLists.txt file, or something else?
- By "follow an include", do you mean like pressing F2?
- When you started the "follow an include" process, are you in the source or build directory?
-
1.)
The folder hierarchy looks like this:build/ |-- ns3/ | |-- class1.h | |-- class2.h | |-- class3.h |-- src/ | |-- modelA | | |--class1.o | | |--class2.o | |-- modelB | | |--class3.o src/ |-- modelA | |-- class1.cc | |-- class1.h | |-- class2.cc | |-- class2.h |-- modelB | |-- class3.cc | |-- class3.h
Thus Waf performs an out of source build. Although it is possible to include every header by specifying its path within the source directory, unfortunately in the project (ns-3) it seems to be convention to refer uniformly to the headers in the build directory via #include "ns3/class1.h", for example. I think waf provides the "build" directory as an include path to the compiler, such that it can find the includes.
2.) I imported the project as an existing project and simply provided custom build and clean commands (e.g. "./waf build" or "./waf clean"). Moreover, I manually set "build" as an include directory to enable QtCreator to find the includes under "build".
3.) Yes, F2 or Crtl+Click
4.) Normally I perform "follow include" when looking at a source file, thus I'm in the source folder. However, it does not seem to matter, as it will always strictly open the file from the include path (which is under "build" because i set "build" as an include path).
-
Hi @bandan,
Thanks for the detailed response, it makes things much easier to understand.
Hmm... I'd say that Qt Creator is doing the right thing. If I hit F2/Ctrl+Click while hovering over
#include "ns3/class1.h"
, I would expect it to open ns3/class1.h and not modelA/class1.h. As far as I know, there's no built-in way to tell Qt Creator to "forward" ns3/class1.h to modelA/class1.h.When I switch header/source QtCreator opens the correct source file.
There's a difference between this action and following
#include "ns3/class1.h"
: When switching, Qt Creator isn't given the path for the file, so it searches the project tree for the file.I don't have experience with writing Qt Creator plugins, so I'll let others comment on how feasible it is to do what you want.
I'm curious: What IDE does the ns-3 developers use? Does it have a similar jump-to-header functionality?
-
Hi @JKSH !
Of course it is correct that QtCtrator opens the file matching the correct path. My problem luckily is not severe but rather inconvenient. I don't know which IDEs ns-3 developers use, but their Wiki lists setup manuals for Eclipse, Netbeans and QtCreator. Seems they do not mind that small problem. I know, however, that some IDEs give you the choice, which file to open, when there are multiple with the same file name indexed. I think Netbeans does this, for example.
I dug around in QtCreators source and to me it seems that there is no easy way to implement such a choice as a plugin. I think the opening via F2/Ctrl+Click is done via follow symbol. The followSymbol functionality in turn is part of the CodeModel (i.e. Clang or classic CPP code model).
Please somebody correct me if I'm wrong.