how can I write (#include <libnotify/notify.h> ) without errors? - qt

I want to apply the simple notification example in the following link
http://www.developer.nokia.com/Community/Wiki/How_to_use_standard_Maemo_5_notifications_in_Qt_applications
I followed the steps and added the 2 lines in .pro
CONFIG += link_pkgconfig
PKGCONFIG += libnotify
but I have the following error when I write #include <libnotify/notify.h>
error: libnotify/notify.h: No such file or directory

Isn't this missing in your .pro file?
INCLUDEPATH += /path_to/libnotify
where path_to is either absolute path like this or relative to directory where your .pro file resides.

Sound like you simply don't have libnotify installed.
Don't know what distro you're using, but something like pacman -S libnotify, apt-get install libnotify, etc. should work.

Related

INCLUDEPATH in qmake project file doesn't work

I've got a problem with include in a qmake project. In my .pro file I've got:
INCLUDEPATH += "C:\OpenCV\build\include"
and in my cpp :
#include <opencv\cv.h>
The compiler indicates an error:
Cannot open include file: 'opencv\cv.h': No such file or directory
but if I write this in my cpp:
#include "C:\OpenCV\build\include\opencv\cv.h"
it works!
I build the project from within Qt Creator. What am I doing wrong?
You have to run qmake(build->run qmake) to validate changes in the pro file.
Qt creator Adding external library (still: Cannot open include file: 'GL/glew.h')
Your problem may be related to the fact that having backslashes in naked #include directives is undefined behavior.
Do the following.
Replace your include with
#include <opencv/cv.h>
Note the forward slash!
Remove the shadow build directory that Qt Creator has made for you. You will find it above the project directory, its name begins with build-.
Rebuild the project.
Note that this takes care of rerunning qmake.
here's one of my pro files:
# Blah Application
TEMPLATE = app
CONFIG += qt console staticlib debug_and_release
QT -= gui
QT += network sql xml
TARGET = blah
CONFIG(debug, debug|release){
DESTDIR = debug
LIBS += -L../../../lib/core/debug -lcore
} else {
DESTDIR = release
LIBS += -L../../../lib/core/release -lcore
}
DEPENDPATH += . ../../lib ../../../lib/core
INCLUDEPATH += . ../../lib ../../../lib/core
# Library files
HEADERS += mtBlahRTP.h
SOURCES += mtBlahRTP.cpp
# Input
HEADERS +=
SOURCES += main.cpp
The include path points to the RELATIVE directory of my lib files. mtBlahRTP.h and mtBlahRTP.cpp are in ../../lib
I have the same question, before building or running, you should qmake(Build=>qmake) it.
My configurations for INCLUDEPATH:
INCLUDEPATH+=D:\opencv\opencv\build\include
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv2
I ran into a similar issue and what I found is that the QtCreator IDE is not re-reading the results of qmake and updating the "Cannot open" message. You need to close the offending file and re-open it - then you'll see that it no longer displays the error.
I had to do two steps: (re-)run qmake and rebuild the whole project - only then the INCLUDEPATH setting was considered correctly. (With QtCreator 3.5 and 3.6 (Qt 5.5 and Qt 5.6) on Windows.)
The only problem you are making is incorrectly linking the OpenCV library. The other answers given here may or may not work, but I have posted on another thread a surefire way to solve this problem using the "Add Library" wizard inside Qt Creator: https://stackoverflow.com/a/51914928/10245006
I was getting the error:
canserialcomm.o: In function `CanSerialComm::CanSerialComm()':
canserialcomm.cpp:(.text+0xc1): undefined reference to `vtable for CanSerialComm'
It turns out that the cause was it wasn't able to find canserialcomm.h where that constructor is declared. This was despite me having INCLUDEPATH in the project file point to the directory containing that header file:
INCLUDEPATH += . \
..
What I had to do to fix this is explicitely specify the header file; I added:
HEADER += ../canserialcomm.h
You should use double backslashes when in windows for qt creator with msvc. like this:
INCLUDEPATH += C:\\libcurl\\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\\include
this will fix the problem.
Under windows you have to eliminate the -I before each directory that is added into the INCLUDEPATH variable.
For example:
Under windows:
INCLUDEPATH += "C:\lib\boost_1_61_0" (back-slash)
Under linux & mac:
INCLUDEPATH += -I"$$(HOME)/lib/boost_1_61_0" (note the -I and forward-slash)
I'm not sure whether it depends on different qmake version or not. But after finishing qmake command, I check the Makefile and the double -I is the issue.
You need to do several things. Fist, in the .pro file, you need quotation marks two backslashes at a time, like this:
INCLUDEPATH += "C:\\OpenCV\\build\\include\\opencv\\cv.h"
You alse need a frontslash in the #include in your .cpp file like this:
#include <opencv/cv.h>
When you've done this, delete the build folder. This is the folder with a very complicated name of the type build-untitled-Desktop_Qt_5_7_0_MSVC2015_32bit-Release. Then, in the Build menu, press "Run qmake". When you've done all this, it should compile fine.
Somehow it did not work for when I had several INCLUDEPATH +=.
When I combined the stuff into a single on it suddenly worked.

How to Include OpenSSL in a Qt project

I'm new to Qt, I've done some Googleing and can't find a detailed enough answer.
I need to use OpenSSL in my qmake-based Qt project. How do I go about downloading/installing/linking it so I can just do an include statement and use its functions in my code?
Assuming Windows, you can download its installation from Win32 OpenSSL Installation Project page. You can choose one for 64-bit windows developing or for 32-bit. Just run the setup and everything will be done easily. The default installation directory is : C:\OpenSSL-Win32
In Qt creator, if you then want to link a library to your project you can just add this line to your .pro file(project file ) :
LIBS += -L/path/to -llibname
So here's what we do for this library( for example to link ubsec.lib )
LIBS += -LC:/OpenSSL-Win32/lib -lubsec
Pay attention to -L and -l.See this question. You don't even need to specify .lib at the end of the library name.
For including .h files add this line to your .pro file :
INCLUDEPATH += C:/OpenSSL-Win32/include
after that you can include a file like this :
#include <openssl/aes.h>
From George at Unable to use AES files of OpenSSL in Qt Creator:
If this is on Linux, add the following into your .pro file:
PKGCONFIG += openssl
It will handle all necessary header paths, compile-linker options and
the libraries.
And make sure you have the openssl-devel package installed in your
system.
I was working on Win 7 (32) with Qt5.5, and non of these answers worked for me.
So I just want to share a solution that finally worked:
1. I have OpenSSL installed in C:\OpenSSL-Win32
2. In c:\OpenSSL-Win32\MinGW there are two library files:
libeay32.a & ssleay32.a
3. I've made a copy of each of them an renamed the extensions:
libeay32.a -> libeay32.lib & ssleay32.a -> ssleay32.lib
4. I linked libraries in my .pro file this way:
LIBS += -LC:/OpenSSL-Win32/lib/MinGW -llibeay32
LIBS += -LC:/OpenSSL-Win32/lib/MinGW -lssleay32
INCLUDEPATH += C:/OpenSSL-Win32/include
5. I copied 3 .dll files from C:\OpenSSL-Win32:
(libeay32.dll, libssl32.dll, ssleay32.dll)
to my build/debug folder:
(build-XXXXX-Desktop_Qt_5_5_1_MSVC2012_32bit-Debug/debug)
I hope this will help.
If you use cmake as build system for your project, then you may include FindOpenSSL.cmake as follows:
#set(OPENSSL_USE_STATIC_LIBS TRUE) # if you want to use static libssl.a and libcrypto.a
include(FindOpenSSL)
#add_executable(${PROJECT_NAME} ...) or add_library(${PROJECT_NAME} ...)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS} OpenSSL::SSL OpenSSL::Crypto)
${CMAKE_DL_LIBS} is required on Linux systems to avoid link-time errors like "dlopen symbol not found...". On windows it became empty.
If openssl installation directory is not being standard, then you should provide OPENSSL_ROOT_DIR to cmake, e.g. to add set(OPENSSL_ROOT_DIR "C:/msys64/mingw32") before include or to specify -DOPENSSL_ROOT_DIR:PATH=C:/msys64/mingw32 to cmake executable (in "Projects"->"Build settings"->"CMake" tab).
if you are on win7,and your qt version is mingw, and u install openssl from http://slproweb.com/products/Win32OpenSSL.html ,make sure your lib should be in the OpenSSL-Win32/lib/MinGW, and add a "lib" pre to the libeay32.a and ssleay32.a 。

Can't link qwt in Qt

I use LIBS flag to link qwt library to my project. So in .pro of my project i have
LIBS += -L/home/Desktop/qwt-6.0.1/lib -lqwt
But anyway Qt does not recognize qwt classes. What i'm missing ??
I think you forgot to include the headers.
Try to add the following
INCLUDE += /home/Desktop/qwt-6.0.1/include
I had same problem. you have to use -L switch and set your library path as bellow:
LIBS+= -L "/home/Desktop/qwt-6.0.1/lib/" -lqwt
adding above line to the .pro file resolve compiling error of the project. then for running Application you should link libqwt.so.6.1.3 to default library path on your system using bellow command:
ln -s /home/Desktop/qwt-6.0.1/lib/libqwt.so.6.1.3 /usr/lib/libqwt.so.6
or simply update LD_LIBRARY_PATH using below command:
export LD_LIBRARY_PATH=/home/Desktop/qwt-6.0.1/lib/lib:$LD_LIBRARY_PATH
I advice you to use the first approach.

Problem with linking

I made a custom library and i compiled it into a dll (qustom.dll).
Now i want to compile another project using this dll.
What i did is to import the header files in the project and add this line in my .pro file
LIBS += -lqustom
but i get "error: cannot find -lqustom"
also i tried
LIBS += qustom.dll
and
LIBS += -libqustom.a
qustom.dll is in the project directory
Also i tried
OTHER_FILES += \
qextserialport1.dll
but didn't work either
Am i missing something here?
Missing a path perhaps? -L/path/to/dlls -ldllname
Qt plays nicely with CMake. I use that and I never get dependency/path headaches like this any more.

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. :/

Resources