z.lib problems while porting qt creator projet to windows - c++

I am trying to port a Qt5.9 project from Mac to Windows 10.
I was able to compile the project easily in a ubuntu installation.
While trying to build it for windows, i had problems with finding zlib include headers with
#include<zlib.h>
That i corrected after following answers here on Stack to
#include<QtZlib/zlib.h>
Now i have problems in LINK phase, it can not open the file z.lib
Problem is i downloaded zlib packages, builds, source code and could not find a z.lib. Only different named libs. Searching in google i could only find people with the same problem, z.lib is not one of the libs included in zlib installation.
This is my project file:
TEMPLATE = app
QT += qml quick widgets websockets
CONFIG += c++11
SOURCES += \
main.cpp \
api.cpp \
app.cpp
HEADERS += \
api.hpp \
app.hpp
RESOURCES += qml.qrc
LIBS += -lz
I tried putting all possible dll and lib files in the project folder. None of them is named z.lib though.

The symbols for zlib are already part of the qt libraries. As long as you do not try to link the zlib explicitly it should work. At least it does work for me.
add to your project file:
!win32 {
LIBS += -lz
}

I managed to solve my problem updating my Qt installation to use MinGw 5.3 32bit. I was using VisualStudio 2015 as the compiler before.
Only changing the compiler to MinGw (g++) 5.3 made everything work with the same pro file i posted in the original question. Thanks everybody who tried to help!

Related

How to implement OpenSSL in Qt?

Trying to use OpenSSL in my Qt project, here is my environment:
OS: Win7 32bit
Qt: Qt Creator 4.2.1 Community
Qt Kit: Qt_5_8_0_MSVC2015_32bit2
Openssl: Win32 OpenSSL v1.1.0e, downloaded form this site
I'm trying to include <openssl/evp.h> in my code, however, when I add #include <openssl/evp.h> in my main.cpp and build, Qt Creator shows the following error: D:\QtProjects\dialogs\findfiles\main.cpp:50: error: C1083: 'openssl/evp.h':No such file or directory
I have already followed the instructions in this question: How to Include OpenSSL in a Qt project
My .pro file looks like:
QT += widgets
HEADERS = window.h
SOURCES = main.cpp \
window.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/findfiles
INSTALLS += target
# for openssl - I added these 2 lines
LIBS += -LC:/OpenSSL-Win32/lib -llibcrypto
INCLUDEPATH += C:/OpenSSL-Win32/include
Please help me fix this.
Posting this as an answer because iam pretty sure i figured it out.
You have to run Qmake before building, otherwise changes in your pro File will not be affected. Since Qmake is compiling your pro File into a makefile
Build->Run QMake
Worked for my OpenSSL library.
Good Luck!

Qt iOS build does not find headers with path

I am building a working application (Mac and Linux) for iOS emulator in Qt 5.4 but when compiling the sources, compiler shows issues about header files not found. These files definitely are where they should be and the same code/pro builds without issues for desktop versions.
For example, in my code I have included:
#include <sndfile.h>
and in my .pro file I have:
LIBS += -L/usr/local/lib/ -lsndfile.1
INCLUDEPATH += /usr/local/include/
and the header file for libsndfile is definitely in /usr/local/include
I have tried adding this to .pro file
INCLUDEPATH+= $PWD
But no use, still all headers that are not directly in the same folder
as the .pro file cannot be found when compiling... What am I missing?
Is there some different way to define paths to iOS build sources?
I am able to build Qt iOS tutorial projects and run them on the emulator.
Perhaps your Makefile is outdated.
Run qmake again, after changing something in .pro file.

link opencv 2.4.6 with Qt library

I am working on windows 7, and installed and compiled OPENCV 2.4.6, it worked perfectly well with microsoft studio 2012, so I know how to find the path of OPENCV include and lib, and configure the path of bin in the system variables
But when it comes to QT, it totally didn't work at all. I know on the stackoverflow there are many questions about how to link opencv with QT in windows, But I tried all the answers, but it never worked out for me.
Here is my configuration which works for visual studio 2012.
system variable path:
D:\Program Files\opencv\build\x64\vc11\bin;
include path:
D:\Program Files\opencv\build\include\;
D:\Program Files\opencv\build\include\opencv;
D:\Program Files\opencv\build\include\opencv2;
lib path:
D:\Program Files\opencv\build\x64\vc11\lib;
I have downloaded and installed QT 5.1.1, and started a project. In the pro, I edited like this,
INCLUDEPATH += D:\Program Files\opencv\build\include \
I assume this should be working, but in the main(), when I added the header
#include "opencv/cv.h"
#include <opencv/highgui.h>
QT compiler will always tell me 'no such file or directory'
This kind of stupid problem has stuck me in for days, I don't know where it goes wrong, could some people help me.
update:
Thanks for everybody, Gibby's answer has helped me to solve the first issue of 'headers can't be found', but now then running the program, I got issues like 'release\test.exe:-1: error:LNK1120: 6 unresolved externals'
so it is definitely due to the linking of libraries , I have tried
LIBS += -LD:\Program Files\opencv\build\x64\vc11\lib \
-lopencv_core246 \
-lopencv_highgui246 \
-lopencv_imgproc246 \
-lopencv_features2d246 \
-lopencv_calib3d246 \
or
LIBS += -LD:\Program Files\opencv\build\x64\vc11\lib \
-lopencv_core246.lib \
-lopencv_highgui246.lib \
-lopencv_imgproc246.lib \
-lopencv_features2d246.lib \
-lopencv_calib3d246.lib \
or from How to link opencv in QtCreator and use Qt library
LIBS += -LD:\Program Files\opencv\build\x64\vc11\lib \
libopencv_core246 \
libopencv_highgui246 \
libopencv_imgproc246 \
libopencv_features2d246 \
libopencv_calib3d246 \
but none of these work
You need to build OpenCV with Qt. The steps are,
Install Qt on your computer (I use Qt4 for all versions of OpenCV since my applications are based on it but you can use Qt5 as well).
Make a note of the install path (for me, it is D:/Qt/4.8.5/ and put it in your Path environment variable.
Open CMake and start the build process for OpenCV. Make sure you select the option WITH_QT under CMAKE.
My CMAKE_INSTALL_PREFIX ss D:/Program Files/opencv and it is there on my Path environment variable`as well; you can change yours accordingly.
Build with other options are required. Generate the files and then build the binaries and install OpenCV in the above mentioned path.
Your OpenCV installation now supports Qt and you can use it inside VS and Qt Creator. For further reference, please head to this link.
HTH
I had the same problem and resolved it by setting the project to release(bottom left in the qt window) instead of debug and then copying the qt and opencv library into the bin folder. Once you have set your project to build a .exe file will be generated in the bin folder. running that application will tell you what dll is still missing, find the opencv dll's at opencv/build/x64/vc11/bin and the qt ones at Qt/Qt(version)/(version)/(compiler)/bin
~Gibby
Because of the space character.
qmake might consider "D:\Program" and "Files\opencv\build\include" as separated.
Just surround your path with double-quotes.

Using SFML with Qt creator?

I've recently began learning the SFML API for learning purposes but it seems to me like it only supports Codeblocks IDE and Visual Studio. I dislike both IDEs for my own ideas and I like the IDE that comes with Qt instead.
Is it possible to basically use SFML within the Qt creator?
EDIT:
I know some of you may some day find this on google, after struggling for 8 days to set up sfml to work with qt creator I've found the sollution:
step 1: Download the VS version of SFML from the website (NOT codeblocks version)
step 2: copy the DLLs from C:\SFML-1.6\lib to your system32 directory
step 3: open qt creator, make a plain C++ project, open your .pro file and add these lines:
INCLUDEPATH += C:\SFML-1.6\include
LIBS += C:\SFML-1.6\lib\sfml-system.lib \
C:\SFML-1.6\lib\sfml-window.lib \
C:\SFML-1.6\lib\sfml-graphics.lib \
C:\SFML-1.6\lib\sfml-audio.lib \
C:\SFML-1.6\lib\sfml-network.lib
And you're done!
Short answer: Yes.
The IDE doesn't really matter all that much. The compiler does. Depending on the compiler used by Qt Creator, you download the appropriate SFML package. Most likely the MinGW based version will work just fine with your default install of Qt Creator. (I believe that relies on MinGW?)
All that then remains to be done is place SFML in its own directory and making sure that you set up the correct paths in your Qt Creator project. There's not much to it really.
I know i'm a little bit late to the party but:
SFML library is 100% compatible with qtcreator especially qmake.
Download SFML from https://www.sfml-dev.org/download/sfml/2.5.1/ . Bottom right minGW (You most likely have mingw on qt)
Place it somewhere you will know where it is. I usually put it in "C:/SFML-2.5.1"
There's a simple copy pasta you can add to your qmake '.pro' file:
INCLUDEPATH += "C:/SFML-2.5.1/include"
LIBS += -L"C:/SFML-2.5.1/lib"
CONFIG(debug, debug|release){
LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-system-d -lsfml-window-d
} else {
LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-system -lsfml-window
}
The 'INCLUDEPATH' includes the headers into your project where as the 'LIBS' adds the library file path. The 'CONFIG()' tells qt if you're running DEBUG mode or RELEASE mode.
This copy pasta is fun because you can also configure a custom wizard and make qt dropdown show you a 'create new sfml c++' project by just editing its profile with this.
Last but not least are the needed .dll files from 'C:\SFML-2.5.1\bin' You can add only the ones you need or all of them if you're lazy. You can do this by copying them into the BUILD folder of your project. (to find the build folder by default its a folder in the same path as your project folder with the name of your project prefixed by 'build-' or 'release-')
Make simple c++ project
Choose QMake build system
in project.pro add 2 lines:
CONFIG += link_pkgconfig
PKGCONFIG += sfml-all

linking mac framework to qt creator

I have a project that uses SystemConfiguration.Framework.
I've been using xcode, where adding the framework is quite easy, just add it to xcode project's framework. But now, I need my project to be cross platform, so I'm using QT Creator as a single IDE, for Windows and Mac. The problem is that I don't know how to tell QT Creator how to link to the systemConfiguration.framework. The header from the framework are correctly included, no problem there... just when is ending the compilation it complains that some symbols where not found, i.e, the symbols that are exported from the systemconfiguration.framework...
Does anyone knows or can help me to set up the Qt creator project to link agains that framework, please?
I assume the project itself is using Qt i.e. it is using .pro files to configure things like include paths and library/framework paths? If so then you just need to update the relevant .pro file to add the framework.
See the qmake docs for more detail. The gist of it is to add
QMAKE_LFLAGS += -F/path/to/framework/directory/
and
LIBS += -framework TheFramework
I found a solution which works with Qt 5.6 here:
https://doc.qt.io/qt-5/qmake-platform-notes.html#creating-frameworks
Using Frameworks
qmake is able to automatically generate build rules for linking
against frameworks in the standard framework directory on macOS,
located at /Library/Frameworks/.
Directories other than the standard framework directory need to be
specified to the build system, and this is achieved by appending
linker options to the LIBS variable, as shown in the following
example:
LIBS += -F/path/to/framework/directory/
The framework itself is linked in by appending the -framework options and the > name of the framework to the LIBS variable:
LIBS += -framework TheFramework