Unable to add include path in Qt Creator - qt

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.

Related

Compiling libwebsocket with newest QT

It appears that libwebsocket is the only library that does not come with Qt, so I think I need to compile it and install it in my QT folder so I can use with other things.
I tried to compile libwebsocket and I got this error:
qwebsocket_p.h:65:10: fatal error: private/qobject_p.h: No such file or directory
#include <private/qobject_p.h>
I believe this is because the QT in my system is old. I have a QT installation in my home folder. How should I pass it to websocket?
If it were with cmake I'd have an idea, but I've heard here https://stackoverflow.com/a/49108604/10116440 that you cannot pass qt folder to qmake. Is there a way to pass to make?
I also tried doing this in cmake:
find_package(Qt5WebSockets REQUIRED)
find_package(Qt5 COMPONENTS Core Qml Quick Svg)
this way I can do cmake -DQt5_DIR=/home/lz/Qt5.11.2 . to set the Qt5 variable for everything except Qt5WebSockets, but the project fails to include <QWebSocket> anyway. If someone knows how to solve this, it'd also be good
private/qobject_p.h: No such file or directory
That means that the directory containing qobject_p.h was not added to the Include paths list. Make sure that your .pro has QT += core-private string.
I have a QT installation in my home folder. How should I pass it to websocket?
It should be enough to put the file named qt.confto the directory containing qmake.exe:
qt.conf
[Paths]
Prefix = <qt root>

How to add library paths in Qt Creator like LIBPATH in Visual Studio?

Question
a) How do we add library paths where the project should look for depended libraries in Qt Creator?
b) How are the settings in project >> Run >> Build Environment related to similar in .pro file? Does the environment variable listed there applies to .pro file as well (well they don't) so what are they exactly?
Context/Details:
Visual Studio has a various environment variables for folders where a project looks for include files, library files or executable files etc. This is rather confusing in Qt Creator and I havne't seen good documentation on it.
The only thing which is obvious is INCLUDEPATHvariable which points to the directories where to look for the include files (.h)
However how do I set the library paths, the path where it should look for dependent libraries/dlls etc? I can specify the exact library with LIBS variable in .pro file, there don't seem to equivalent of LIBPATH variable where it should look for other libraries if not found in current folder.
I have worked around this be adding library path the following way basically using LIBS variable but dropping the library file name and that seems to work and add the path but I don't see this documented anywhere.
LIBS += -L"$$_PRO_FILE_PWD_/Xerces/bin/"
But what makes things more interesting is the settings in Projects >> select 'Run' from current configuration and expand the Run Environment settings.
''
Here there is LIB variable and LIBPATH variable but there are clearly not .pro environment available. It also says here that these settings are local to user and saved in .pro.user file which perhaps suggest it's a different way to set but it doesn't say how to set them in .pro file but it does suggest to set them there if want to apply for all users!
Likewise there are DEPENDPATH AND VPATH and it is not really clearly what they are used for.
I don't have enough Rep to add comments to your question, So am adding my comment in form of answer. I am pretty new to Qt and have been developing Qt GUI application on Linux.
I set this LD_LIBRARY_PATH environment variable with the path to my Qt libraries. Am not sure how much it will be helpful to you since you are using visual studio on windows.
in Projects property go to Build Environment and add a variable with the libs path, example NAME_LIBPATH. So in the .pro file add the following:
# your lib configuration
LIBS += -L$$(NAME_LIBPATH) \
-llibname

Set Additional Include Directories in Qt Creator

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.

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 :)

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