Set Additional Include Directories in Qt Creator - qt

I am using Qt Creator to rewrite my former project which is developed in Visual Studio. In this project I need to use an external library (gloox for xmpp).
Here's what I did in Visual Studio:
Add c:/dir1/ to the Additional Include Directories, that's where the tons of .h and .cpp files are.
Add c:/dir2/ in the linker setting, that's where the .lib file is.
I want to do the same thing in Qt Creator, so I added INCLUDEPATH += c:/dir1/ to the end of my .pro file, but when I qmaked again I still could not include anything from dir1 successfully.
#include <message.h>
C1083: Cannot open include file: 'message.h': No such file or directory
What should I do?

Based on the comment discussion, the problem seems to be that, after the INCLUDEPATH and potentially other relevant modifications, you forgot to properly re-run qmake.
This is necessary when dealing with QtCreator unfortunately due to the following long-standing issue:
Creator should know when to rerun qmake

I found the solution: copy everything in the .pro file and delete the .pro file. Then create a new .pro file and copy everything back, then execute qmake then run.

Related

Unable to add include path in Qt Creator

I've downloaded a C++ project which uses Boost. It's rather complicated and plenty of files reference its parts, like:
#include <boost/graph/fruchterman_reingold.hpp>
I've put Boost directory in the project folder and added INCLUDEPATH += "C:/Programming/my-project" in the .pro file but for some reason Qt keeps telling me "No such file or directory" about every single file. Now note that if I change the paths to absolute the references start working. I've ran Qmake explicitly but still get the same problem. What can I do about it besides changing all paths to absolute?
I'm running Qt Creator 3.3.0, Qt 5.4.0, the compiler is MinGW 4.9.1.
So I've figured it out. Apparently the project had several projects inside but I wasn't aware that I had to change .pro files in every single one to tell the compiler to add a new path. After I did it the problem was solved. Thank you for your time, people.

Qt creator can not include opencv header files

I have downloaded qt-5.0.0 for windows.
http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe
I have added INCLUDEPATH += C:\opencv\build\include in the .pro file.
Opencv 2.4.3 is already installed.
When I include header file in qtcreator :
#include <opencv2/opencv.hpp>
There is compilation error : can not find opencv2/opencv.hpp
Any ideas ??
I found the solution. In Qt Creator, goto Projects on the left pane ( ctrl+5), then Build Environment -> Use System Environment, click on Details. Edit LIB variable. Add here.
Things to check:
does C:\opencv\build\include\opencv2\opencv.hpp actually exist?
does the compile command (which you can check in the Qt Creator "compile output" window) show -IC:\opencv\build\include argument in the compile command?
qmake should be run automatically after modifying the .pro file, but re-run it manually just in case (for example from Build menu), as suggested by the first answer
this should not have any effect in issue like this, but just in case: if you are using "shadow build" (which is a good idea), make sure the source dir is clean of any generated files
The correct header files are:
<opencv2/core/core.hpp>
<opencv2/imgproc/imgproc.hpp>
<opencv2/highgui/highgui.hpp>
… and so on. The include of "opencv.h" is deprecated!
It also does not work anymore for QtCreator auto-completion.
The solution is to update your sources to use the correct header files.
After any change made to .pro file , Do right-click on project folder and click on run qmake .
Well, I just ran into this problem tonight. luckily enough, after taking a fair time, the solution was found. If your project is managed by qmake, and Qcreator is used, just go to the Build->Run qmake, then build and run your project. A tip, whenever you change your *.pro file, remember to rerun Build->Run qmake, because that will reconfigure your project.
If this helps you, please give me a thumb up :)

Can I get qmake -project to add LIBS += .... to my .pro file?

I have a project that uses Qt. So I have "qmake" make my Makefile from the .pro file. But Qmake can also make that .pro file: qmake -project . This worked until I needed to add an external extra library to my project.
I get lots of hits on google that tell me to add LIBS += ... to my project file, but I want to tell qmake -project something that causes it to add it for me. In effect of course I'll be doing it myself, but I don't think that it's proper that I am editing the generated project file.
If for example I add files to the project directory, I'll have to recreate it and add in the library again, or I'll have to manually add the files to the (almost completely computer-generated) project file. I'm now using a script to auto-generate the project file, and then add in the LIBS += directive, but is there a proper way to do this?
When you are developing without the Qt Creator IDE, unless the IDE includes by itself some automatic utilities, you must edit manually the .pro configuration file.
The generated .pro file is a skeleton file which YOU must fill in with the libraries that you need, then the qmake system figures out the other dependencies and compiles your project. It is a essentially a much better version of pkg-config of gtk + Makefiles.
When you add more source and resource files to your project then manually you must add them to the .pro file.
Example:
QT += core gui
TARGET = qtcp1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
miwidget1.cpp \
lcdrange.cpp
HEADERS += mainwindow.h \
miwidget1.h \
lcdrange.h
FORMS += mainwindow.u
Alternately, you can issue qmake -project over and over again, but this can cause some unforseen accidents, since it includes everything that is in the current directory at the time, including the pre-processed files for conversion to standard C++ from QT dialect. This intermediate files must be erased (cleaned), before the remaking the project and the next make or can lead to tricky problems.
Using the official and free QT Creator IDE takes away most of this burden by adding automatically the new data to the .pro file and cleaning loose ends. Some other IDEs like Code::BLocks and Codelite provide some facilities for QT, but not to the level of QT creator. Some prefer to edit the .pro themselves for custom reasons, other like more other styles of IDEs, like Eclipse.
You should test the waters and decide by yourself what fits best to your needs.
ReEdited, to clarify a few things.

Does the qmake includes pri files automatically in the pro file

Assume the following directory structure
project/project.pro
project/project.pri
In this case even if the project.pro file does not have a statement like (include project.pri). Does it gets included automatically by qmake.
In the qtcreator sources plugin directory
qt-creator/src/plugins/coreplugin
There is a coreplugin.pri file which is not included in the coreplugin.pro file
I'm fairly confident that it does not get included automatically, and I did a quick test with a .pro and a .pri file that had message calls in them to confirm this.
With regards to the files you're seeing in creator, it's not uncommon to have a .pri file that is designed for other .pro files to include so that you can use the project.

QtCreator's code completion doesn't work for Qt libs

When trying to work in QtCreator, there is a problem with code completion for Qt libs. QtCreator says that it can't find Qt headers, so no code completion for them. I.e. if I write #include <QPainter> or #include <QtGui/QPainter> this line gets underlined with message No such file or directory.
But nevertheless compilation process works flawlessly. So, qmake finds everything correctly and the problem is in the QtCreator. Also, code completion works normally for all own files (created for project).
We've tried numerous fixes including reinstalling Qt twice, trying to mangle with qt.conf in QtCreator's dir, tried to find qmake.cache, searching the registry and googled a lot. We're using QtSdk 1.1 with bundled QtCreator 2.2.1 under Windows Vista, installed in the default location.
There is dirty solution to write path in .pro file, but we don't want to use it.
Choose one of the following files
Qt_install/mkspecs/common/your_os.conf
or
Qt_install/mkspecs/common/your_compiler.conf
By Qt_install I mean the directory where Qt is installed (not qt creator), e.g. C:\Qt\Qt 4.7.4\ and your_compiler should be mingw I guess (don't have a windows install).
In the .conf file, add the line with the path you added in your .pro, something like:
INCLUDEPATH += path1 path2 ...
The mkspecs files are implicitly included in all your .pro so code completion will work in all your projects.

Resources