Adding each subdirectory's path to qt pro file variable - qt

I want to add path of each subdir having .h file to a qt pro file variable
I found this http://doc.qt.digia.com/qt/qmake-project-files.html#built-in-functions-and-control-flow for use of a for loop but don know how to use if to do above task.
INCLUDEPATH +=$$(MITK_INCLUDE_PATH)
When I wrote this (where path variable having only outer dir's path) its allowing me to include a header in source as:
> #include"ITK-src/Code/BasicFilters/itkAbsImageFilter.h"
and qmake is running properly but when I am building this project its asking for another .h on which above .h depend. Before this I have worked with adding 3'rd party libs in which I gave path of each header file's location to INCLUDEPATH as here but if there is any other way I want to know possibility.

Related

Organize Qt project files in folders, and simplify the includes

Brief
How do I tell my sub-project which are its subdirectories, in pro file, and not have to prefix the subdirectories in each #include directive ?
Problem description
I have a large project, containing multiple libraries. Also, I am looking at one library that has a large number of classes. I am trying to organize it in such a way that it is easier to see everything at a glance.
I am using Qt Creator. The only way to make the logical grouping I am thinking of, is to create folders.
The "pro" file looks logical:
SOURCES += sample.cpp \
class1.cpp \
class2.cpp \
interfaces/interface1.cpp \
interfaces/interface2.cpp
In each file that I must include one of the headers I must also add the folder:
#include "interfaces/interface1.cpp"
I would not give this a second thought, except...
For an outside library or application, I can add in their pro file (or include a pri file) to tell where the current library files are located:
INCLUDEPATH += $$PWD/../Sample
INCLUDEPATH += $$PWD/../Sample/interfaces
This creates the magic: from any outside library or application, I don't need to prefix the include directive with the folder location.
#include "interface1.cpp"
I have not been able to make this work from the current project. I don't understand why, I would like to know how to make it so that I no longer need to ad the folder path in the include directives (while still keeping the visual logical organization of my files).
Summary
For the structure above, adding
INCLUDEPATH += $$PWD/../Sample/interfaces
In the po file for an outside project allows me to include files like this:
#include "interface1.cpp"
I want to be able to do the same from the current project files. Right now, I am forced to include files like this:
#include "interfaces/interface1.cpp"
Create .pri file for subdirectory. And include .pri in .pro file.

If you include a .pri, shouldn't that .pri's include path affect your #includes?

If I include(someOtherProject.pri) in my .pro, and that other project file (.pri) has INCLUDEPATH += . in it, then shouldn't my files in my .pro find those headers when I #include them? I cleaned and ran qmake on everything, regenerated the .pri file by simply copying the .pro from that other project and renaming it with the .pri extension, but when I #include a file from that other project, compiler says it cannot find it.
I wouldn't expect that I must also edit the INCLUDEPATH of my working .pro file if I am already using include(someOtherProject.pri) -- that would make the point of using include(someOtherProject.pri) unnecessary altogether.
The solution is to have INCLUDE PATH += $$PWD/ in the .pri instead, as this will expand out to the proper hard-coded path no matter where it is included.

Qt Error: cannot open include file: 'opencv2/core/core.hpp' no such file or directory

I want to build an opencv project using Qt 5.1_VS2010. I have included the path for opencv include files. But when I run the code, I get the error that specific .hpp file does not exist! I have checked in the directory and it actually exists there! another point that when I was trying to include it in my main c++ file, the auto completion guide actually helped me complete the whole path! so it means the directory and the header file was already recognized! anyway, part of my .pro file that includes the path is like this:
INCLUDEPATH += "C:/opencv/build/include"

How to include a .lib file dynamically?

I've got a problem with my project. I am developing it on Qt Creator, and I need to add a .lib file to my project. So, I wrote this line in my .pro :
LIBS += "C:\My_Path\My_Project\lib\file.lib"
This is working fine. My only issue is that I need to write the entire path to the .lib file. Since it's a group project, it needs to be compilable on other computers without changing the path to this file every times.
I tried many syntaxes, like :
LIBS += -L"lib/" -l"file.lib"
or
LIBS += "lib\file.lib"
or
LIBS += "file.lib"
(putting the .lib file at the root and adding it to the project in Qt Creator)
None of them works :/
I also tried to add the .lib file in a QResource file but a syntax like this one :
LIBS += ":/lib/file.lib"
in a .pro file doesn't seem to work...
I am now running out of ideas :(
Help please :)
Did you try
LIBS += -Llib -lfile
or
LIBS += -L./lib -lfile?
Remember if you aren't using the full path, you don't add .lib to the library name and you don't use quotes. If the path has spaces (or you just want to be safe), use $$quote(-L<path name>)
As stated here the Unix style paths work on Windows as well where you normally need to provide the full path. qmake will fill it in for you.
I converted
LIBS += ../../lib/phraseBox.lib
to
LIBS += $$quote(-L../../lib) -lphraseBox
and
LIBS += $$quote(-L../../lib) phraseBox.lib
In one of my project with no problem on Windows. You might want to post your project files somewhere, or post the actual error messages to narrow this down.
Ok, I found the solution :
the lib/ directory has to be placed in the same directory that the Makefile (the real one, not the .pro).
Since I copied the lib/ directory in the build-desktop/ directory, everything is working fine using relative paths :)
From your tries I guess you want to link to the library using relative path which should work just fine by default.
Try this:
LIBS += -L$$relative/directory/path -llibname
If it does not work, then you might want to try setting multiple INCLUDEPATH. :/

How do i reference the qjson.dll file from my qt project?

How do I refernce the qjson.dll file from one of qt project?
For eg :C:\qjson-0.7.1\qjson\build\lib , in this location, I have qjson.dll and qjson.dll.a file. I want to use that dll from my qt project.How should I point to that location in that .pro file. I can't compile successful, the error that I got is
C:/QTTest/foo/foo/main.cpp:6: error: Qjson/parser.h: No such file or directory .Can someone can help me?
Thx.
First, you have to tell QMake in your .pro where is located your header files using the INCLUDEPATH variable (please correct the path to point the location of your Qjson folder):
INCLUDEPATH += "c:/qjson-0.7.1/include"
Second, you must specify your library and it's location using LIBS variable:
LIBS += "c:/qjson-0.7.1/qjson/build/lib/qjson.dll.a"
Now, QMake will find your header file and your library. You will need to have the qjson.dll in the same directory as your Qt application or to add it's location in your PATH environment variable.

Resources