Qt creator can not include opencv header files - qt

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

Related

Qt using CMake: ui_mainwindow.h: No such file or directory

I use Qt with CMake because CMake integrates with my team's work easier than my own. I have frequently encountered an error along the lines of
ui_*.h: No such file or directory
Usually when my project already has a ui_*.h file to start with it will just modify that .h file. I do use the below commands in my CMake file, so it should be wrapping my .ui file with the appropriate ui_*.h file.
qt4_wrap_ui (mainwindow mainwindow.ui)
target_linked_library (mainwindow ${QT_LIBRARIES})
But sometimes that doesn't work and I have to completely rebuild the entire ui_*.h file. What am I doing wrong?
For anyone having this problem in the future. I pretty much followed the demo here.
http://doc.qt.io/qt-5/cmake-manual.html
Adding, the following line to the CMakeLists.txt should get rid of this problem.
set(CMAKE_AUTOUIC ON)
From the CMake documentation at
https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOUIC.html
AUTOUIC is a boolean specifying whether CMake will handle the Qt uic code generator automatically, i.e. without having to use the QT4_WRAP_UI() or QT5_WRAP_UI() macro. Currently Qt4 and Qt5 are supported.
One small note, this property is available in CMake versions 3.0.2+. So below that, #rbaleksandar's solution should be more appropriate.
Hope that helps.
The quick solution is to use UIC. In bash navigate to the directory containing your *.ui file and run (for the mainwindow.ui example)
uic mainwindow.ui -o ui_mainwindow.h
and then move the newly generated ui_mainwindow.h file to your build directory.
mv ui_mainwindow.h ../build_Qt_4_8_5-Debug/
You shouldn't see the 'No such file or directory' error anymore and can confidently move on to the many other wonderful errors to find in the world of Qt with CMake.
If I remember correctly you actually have to add your UI files to the add_executable(...) like this:
qt4_wrap_ui(UI_HEADERS mainwindow.ui ...) # Add all UI files here like you've done it
...
add_executable(${PROJECT_NAME} ${SRC} ${UI_HEADERS}) # Add them to the executable
...
After all UI files are actually converted to header and source files, which naturally have to be compiled along with the rest of your code.
Building with CMake seems to have an error in
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
remove if in your CMakeLists.txt like this:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
This works in my system with CMake 3.12.1 and Windows 10.
when the ui files are stored in a different location the CMAKE_AUTOUIC_SEARCH_PATHS can be set to include the custom locations so that the CMAKE_AUTOUIC option will find the ui files.
None of the previous answers have helped me.
I tried Ctrl + RMB on #include "./ui_mainwindow.h" in Qt Creator and after that the error did not appear since.
Few details to mention:
set(CMAKE_AUTOUIC ON) was enabled before add_executable()
cmake_minimum_required(VERSION 3.5)
I was using qt6

Another "No such file or directory" error in qt5

So, I encounter another interesting "no such file or directory" error in my program.
The interesting thing is, when I typed the classes I include in my source code, which are QGraphicsItem and QGraphicsView in this case, no warning was given. But when I tried to built it in Qt creator, it raise an error and told me that "C1083: can not open include file:No such file or directory". (The header file both locate at D:\Qt\Qt5.4.1\5.4\msvc2013_64\include\QtWidgets)
Also, I went check the include path in my qt5.4 file, which is D:\Qt\Qt5.4.1\5.4\msvc2013_64\include in his case, I did exactly find the two header files.
Has any one met this error before? Can explain it?
And by the way, which is the default include path in qt creator and how to change it?
You should check your .pro file for this line:
QT += core gui widgets
I would recommend to add widgets to your QT variable.
Yhis should solve your problem with path to all headers, which are realted to QtWidgets.
Don't forget to rebuild your project after editing .pro file.
In case you are building it from console you should:
cd to your project dir
Run qmake
Than run make
In case you are using QtCreator you should use Rebuild option

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.

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.

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