QGIS cannot find headers file - c++

I'm trying to create a custom QGIS desktop application with Qt 5.9.1
I have downloaded OSGeo4W (x64) geospatial software set and the Github C++ QGIS samples but I'm facing an error at compile time:
Cannot open include file: 'qgsmapcanvas.h': No such file or directory
Actually none of the above headers files are under OSGeo4W folder:
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmaplayerregistry.h>
#include <qgsrasterlayer.h>
#include <qgsmapcanvas.h>
But..shouldn't they be in dll libraries (eg qgis_core, qgis_gui ... ) ?
Anyway, this is my *.pro file:
TEMPLATE = app
TARGET = qgis_example4
QT = sql network svg gui core xml
LANGUAGE= C++
INCLUDEPATH += "C:\\OSGeo4W64\\include"
LIBS += -L"C:\\OSGeo4W64\\apps\\qgis\\bin" -lqgis_core -lqgis_gui -lgdal_i -lgeos_c
DEFINES+=CORE_EXPORT=__declspec(dllexport)
DEFINES+=GUI_EXPORT=__declspec(dllexport)
CONFIG += qt gui exceptions stl warn_on debug thread
RESOURCES += resources.qrc
FORMS += mainwindowbase.ui
HEADERS = mainwindow.h
SOURCES = main.cpp \
mainwindow.cpp
PS: there is a similar question on stackiverflow but I repeated it because the answers given did not give the solution

Solved: the needed headers file could be found within the "qgis-dev" branch of the project.
OSGeo4W : For users that cannot use OSGeo4W for some reason or just prefer it there is also a weekly snapshot of qgis-dev from OSGeo4W as standalone installer
After the installation you can find header in:
C:/Program Files/QGIS 2.99/apps/qgis-dev/include
So this is my .pro file
TEMPLATE = app
TARGET = qgis_example4
QT = sql network svg gui core xml
LANGUAGE= C++
INCLUDEPATH += "C:/Program Files/QGIS 2.99/include"
INCLUDEPATH += "C:/Program Files/QGIS 2.99/apps/qgis-dev/include"
LIBS += -L"C:/Program Files/QGIS 2.99/apps/qgis-dev/bin" -lqgis_core -lqgis_gui
DEFINES+=CORE_EXPORT=__declspec(dllexport)
DEFINES+=GUI_EXPORT=__declspec(dllexport)
CONFIG += qt gui exceptions stl warn_on debug thread
RESOURCES += resources.qrc
FORMS += mainwindowbase.ui
HEADERS = mainwindow.h
SOURCES = main.cpp \
mainwindow.cpp
Although the files are now present, I still not able to run QGIS samples. Maybe I'll move to other sample or I'll do my custom basic application.

Related

How to add the built from source boost library to qt creator on linux

I compiled the boost library from the source using the scripts that came with the source (below the commands that I wrote)
/bootstrap.sh —prefix=/libs
./b2 install
After the build, 2 new directories appeared in the libs directory, include and lib, respectively.
Next, I registered the path to boost in the pro file qt creator
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
INCLUDEPATH += I-/libs/include/boost
LIBS += -L/libs/lib
In theory, I specified the path to both the headers (include / boost) and the binaries (lib), but nevertheless, when I try to compile the test code, I get a bunch of errors. How to correctly register a pro file if I want to connect asio, on Linux, where did I go wrong? (set of errors)
You are not giving the library name in LIBS, only giving the path. Correct format is:
LIBS += -L<pathToLibrary> -l<libraryName>
Moreover INCLUDEPATH syntax is also incorrect. There's no need for I-.
INCLUDEPATH += /path/to/library
# e.g
INCLUDEPATH += libs/include/boost
And btw you don't need to link to anything if you are using asio only, since as far as I remember, Asio is header only so only include path will be necessary.

Importing libssh into Qt

I'm currently trying to import libssh into a Qt project I am working on. It appears that I have the library linked correctly as the project builds, but once I run the project it just crashes before anything really starts up. Which makes debugging difficult. If I comment out the line:
my_ssh_session = ssh_new();
Then everything runs as it should and no crash occurs. My .pro file looks like
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += sql
QT += script
QT += scripttools
QT += uitools
LIBS += -llibssh
INCLUDEPATH += $$quote(C:\libssh\include)
TARGET = white_wrapper
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
datafeeder.cpp \
dbfeeder.cpp \
xmlhelper.cpp \
hiddevice.cpp
HEADERS += mainwindow.h \
datasource.h \
datafeeder.h \
dbfeeder.h \
xmlhelper.h \
hiddevice.h
FORMS += mainwindow.ui
After looking online it looks like the problem could be dlls but after running a dll dependency application it looks like I have all the dlls needed so I guess I'm at a lose and would love some input thanks.
I was getting the same error message with libssh-0.7.1, Qt 5.2.1 and MinGW.
After some research it turned up that libssh
needs another two dynamic libraries which depends on: libeay32.dll and zlib1.dll. They are not included in libssh's distribution archive, therefore you have to download them yourself and copy next to libssh.dll (or somewhere on $PATH).
In my .pro file I have the following lines added (I installed libssh using their installer to Program Files (x86) directory):
# Libssh:
LIBS += -L$$PWD/'../../../../../Program Files (x86)/libssh/lib/' -lssh.dll
INCLUDEPATH += $$PWD/'../../../../../Program Files (x86)/libssh/include'
DEPENDPATH += $$PWD/'../../../../../Program Files (x86)/libssh/include'
Now my Qt application works without problems.

Error : undefined reference to 'engOpen'

Please, I'm looking for a solution to this problem
erreur : undefined reference to 'engOpen' when I try to call mtlb function for c++
I'm working on win64 with QT creator.
Here is my .pro file:
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
INCLUDEPATH += "C:\Program Files\MATLAB\R2012a\extern\include"
LIBS += -L "C:\Program Files\MATLAB\R2012a\bin\win64"
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
LIBS += -L "C:\Program Files\MATLAB\R2012a\bin\win64"
You're only setting the lib path, you also have to point to the lib file:
LIBS += -L<path> -l<file without extension>
On Windows you can also just set the full path (with file), but the above format should work both with Unix and Windows. In your .pro you're mixing the Unix format and the Windows format.
Cf the Qt documentation.

Qt Creator linker error: LNK1104: cannot open file 'opencv_core249d.lib'

I'm building a Kinect app using Qt and C++ and I need to use the OpenCV library. I have correctly installed OpenCV and included the OpenCV header <opencv2\opencv.hpp> in my source file, and that's the only header I'll be using. I tried building my project in visual studio and it worked out fine, but now I'm trying to build the project in Qt Creator and it's giving me this build error:
LNK1104: cannot open file 'opencv_core249d.lib'
So here is my project file:
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------
TEMPLATE = app
TARGET = MM_demo
DESTDIR = ../Debug
QT += core opengl widgets gui
CONFIG += debug
#include directories
KINECT_INC_DIR = $$(KINECTSDK10_DIR)inc
OPENCV_INC_DIR = $$(OPENCV_DIR)\include
#library directories
OPENCV_LIB_DIR = $$(OPENCV_LIBRARY_DIR)
KINECT_LIB_DIR = $$(KINECTSDK10_DIR)lib\amd64
DEFINES += QT_OPENGL_LIB QT_WIDGETS_LIB
INCLUDEPATH += $$KINECT_INC_DIR $$OPENCV_INC_DIR
DEPENDPATH += $$OPENCV_LIB_DIR $$KINECT_LIB_DIR
message(opencv lib directory $$OPENCV_LIB_DIR)
message(kinect lib directory $$KINECT_LIB_DIR)
LIBS += -L"." \
-lopencv_core249d \
-lkinect10 \
MOC_DIR += ./GeneratedFiles/debug
OBJECTS_DIR += debug
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(MM_demo.pri)
I'm using Qt 5.5.2 MSVC2013 64bit on Window 8.1. My OpenCV environment variables are: OPENCV_DIR: C:\opencv\build and OPENCV_LIB_DIR: C:\opencv\build\x64\vc10\lib
My OpenCV include directory is C:\opencv\build\include and its library directory is C:\opencv\build\x64\vc10\lib. I'm sure I have put the right include and library paths in the .pro file. I've been searching for a solution all day and saw some similar linker issues on the web but none of them solved my issue. I'll be thankful to anyone who has an idea of what's going wrong with my .pro file or anything else.
You have set OPENCV_LIB_DIR as environment variable but it needs to be OPENCV_LIBRARY_DIR because the operating system has no information on the first term in the line below but it will look for the second variable:
OPENCV_LIB_DIR = $$(OPENCV_LIBRARY_DIR)

Opencv sample in Qt crashes immediately with the error 'The program has unexpectedly finished'

I tried to create a simple Opencv application in Qt and upon running, the whole application is crashed. If I comment out the opencv related codes from the project, the project runs just fine.
What I did:
Downloaded the Qt 5.5.0 VS2013 64bit version
Downloaded the OpenCV 3.0
Downloaded the Cmake 3.3.2
There were already prebuilt binaries in when I extracted the Opencv package, But all tutorials on the net wanted me to recompile the source codes so did I. The package contains:
build
sources
created a new folder named mymade to hold the binaries next to the other two directories. So it now looks like this:
build
mymade
sources
Steps:
Fired up CMake, specified the source folder from the extracted files
and specified mymade as the output for binaries.
checked all options that had a opencv in their names, plus Qt! and configured it and subsequently generated the files.
This is the resulting contents:
So all is done and I now need to build the binaries. I opened OpenCV.sln and compiled the release and debug binaries. The dlls are placed inside bin directory, and the lib files are placed inside lib folder.
Now it's the time to configure the Qt projects .pro file, so I used the header files from build directory, and for libs I used the lib folder from mymade folder. This is the first configuration that I came up with, which compiles without any linker issues, but crashes just immediately.
The initial changes in project file :
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib
FORMS += mainwindow.ui
Doing this in project file as it was suggested by answers like this didn't do any good either:
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib
FORMS += mainwindow.ui
This fails as well:
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300
FORMS += mainwindow.ui
So what is the problem here?
Update
As it was pointed out by #Miki, Qt couldn't find the opencv dlls (the configs above were OK but), And to solve this problem, one only needs to add the directory containing dlls to the PATH variable, there you are good to go and everything should be fine now.
From the comments to question it turns out that the program didn't find OpenCV dll.
You can:
Copy the required dll in the same folder of the .exe
Add the folder containing the dll to the PATH. You need to restart Qt Creator for changes to take effect.