How do I set up OpenSSL for Qt on Windows 10? - qt

I'm attempting to install OpenSSL on Windows 10 for use with Qt development. I've tried installing from multiple sources, adding lines to my .pro file, and adding DLL files next to the built application, yet nothing works.
I've tried building and running the Qt HTTP request example, and that can't use HTTPS either, so it's not an issue with my code or configuration.
So, where should I get OpenSSL for Windows, and what do I do after installing it?

I've done this before.
For starters, you need to build OpenSSL 1.0.2 source code - available here. You'll need to follow the build instructions in the INSTALL.W32 file. And there are some amended instructions in the INSTALL.W64 file for 64-bit builds.
The two primary DLLs you will wind up building are libeay32.dll and ssleay32.dll. (Also copy off the libeay32.lib and ssleay32.lib stub files and corresponding .pdb files).
If your Qt sources are already built for OpenSSL, you can just drop these two DLLs into your Qt Bin folder (or wherever Qt5Networking.dll is loaded for your application).
If your Qt distribution is built from source, you might need to build Qt again with the openssl-linked option. This will enable Qt to be loaded via implicit DLL loading.
LIB=%LIB%;%c:\openssl\out32dll
configure -commercial release -opengl dynamic openssl-linked -force-debug-info -nomake examples -llibeay32 -lssleay32
jom
For a debug build to correspond to debug Qt5 binaries, you'll need to repeat the above steps, except follow the OpenSSL instructions for building debug binaries to the out32dll.dbg folder.
If your qt distribution was built with dynamic openssl loading, you just need to make sure ssleay32.dll and libeay32.dll are in a folder that is in your PATH environment variable.

Related

Conan-based Qt installation uses wrong home dir for linking

I'm trying to build our application using Qt 5.13.0 installed via Conan/Artifactory. We run our own Artifactory server and the Qt version there is self-build (and statically linked) in our CI solution. We use the Conan recipe for Qt written by the bincrafters, slightly modified to apply some patches for known Qt bugs and set some flags for building properly on Android and WebAssembly.
When trying to build the application, the linker fails to find the necessary dependencies for Qt itself because it tries to look them up in the home folder of the user who build the Qt package, not the user who's running the build.
Here's an excerpt from the build log, showing the attempt at linking all previously compiled object files together:
application folder-------v subproject of the application----v-------v dependency of the application, correct user home dir---------v Qt library installed via Conan, correct user home dir-------v dependency of Qt, WRONG user home dir------------v
g++ -Wl,--gc-sections -o ../../fah [--> all the .o files <--] -L../lib -lmodel -lcore [--> more linked libraries and application parts <--] -L/home/kaupes/.conan/data/libsodium/1.0.18/bje/stable/package/d1efe3774eed76670888f919621e7c4e1b52efa9/lib /home/kaupes/.conan/data/qt/5.13.0/bje/stable/package/d6b3f512e1a5607061462f94e3271dc8af3dd516/lib/libQt5Gui.a /home/dev/.conan/data/harfbuzz/2.4.0/bje/stable/package/c68551ae35bf5d62e66263379d58a38416eb84a9/lib/libharfbuzz.a [--> many, many more libraries <--]
g++: error: /home/dev/.conan/data/harfbuzz/2.4.0/bje/stable/package/c68551ae35bf5d62e66263379d58a38416eb84a9/lib/libharfbuzz.a: No such file or directory
many, many more errors...
As you can see, the user running the build is kaupes, but the g++ invocation attempts to look for the dependencies in /home/dev/, the home folder of the CI user who build the Qt Conan package.
Only dependencies of Qt itself have the problem. Dependencies of the application (also installed via Conan) are found at the correct place.
The Qt package has been build in the CI using the following Conan invocation:
conan create --profile .conan/profiles/linux -s compiler=gcc -s compiler.version=9 . fah/stable
Compiler and version are explicitly set because I'm also build for another GCC version. The linux profile file also doesn't do anything interesting (as far as I can see):
include(default)
[settings]
build_type=Release
compiler.libcxx=libstdc++11
[options]
OpenSSL:shared=False
OpenSSL:no_asm=True
OpenSSL:no_asm=True
OpenSSL:no_weak_ssl_ciphers=True
OpenSSL:no_ssl2=True
OpenSSL:no_ssl3=True
OpenSSL:no_engine=True
libcurl:shared=False
libxml2:shared=False
libxml2:fPIC=True
libsodium:shared=False
pcre2:shared=False
libpng:shared=False
freetype:shared=False
bzip2:shared=False
libjpeg:shared=False
harfbuzz:shared=False
xkbcommon:shared=False
qt:shared=False
qt:with_glib=False
qt:with_sqlite3=False
qt:with_mysql=False
qt:with_pq=False
qt:with_odbc=False
qt:with_sdl2=False
qt:with_openal=False
qt:with_libalsa=False
qt:openssl=True
qt:commercial=False
qt:qtsvg=True
qt:qtdeclarative=True
qt:qtactiveqt=False
qt:qtscript=False
qt:qtmultimedia=False
qt:qttools=True
qt:qtxmlpatterns=False
qt:qttranslations=True
qt:qtdoc=False
qt:qtrepotools=False
qt:qtqa=False
qt:qtlocation=True
qt:qtsensors=True
qt:qtwayland=True
qt:qt3d=False
qt:qtimageformats=False
qt:qtgraphicaleffects=True
qt:qtquickcontrols=True
qt:qtserialbus=False
qt:qtserialport=False
qt:qtx11extras=True
qt:qtmacextras=False
qt:qtwinextras=False
qt:qtandroidextras=False
qt:qtwebsockets=True
qt:qtwebchannel=False
qt:qtwebengine=False
qt:qtwebview=False
qt:qtquickcontrols2=True
qt:qtpurchasing=False
qt:qtcharts=True
qt:qtdatavis3d=False
qt:qtvirtualkeyboard=True
qt:qtgamepad=False
qt:qtscxml=False
qt:qtspeech=False
qt:qtnetworkauth=False
qt:qtremoteobjects=False
qt:qtwebglplugin=False
qt:qtlottie=False
qt:qtconnectivity=True
Is there something I'm doing wrong during the Conan package creation or installation or is this caused by something different?
Indeed, when building qt, all paths to dependencies are hardcoded in configurations files (mkspecs\modules\qt_lib_*.pri).
I assume you are building your application with qmake, because you use static qt, and static qt is incompatible with cmake. One thing you could try is to pass the full path to harfbuzz lib to qmake by adding argument QMAKE_LIBS_HARFBUZZ=/home/kaupes/.conan/data/harfbuzz/2.4.0/bje/stable/package/c68551ae35bf5d62e66263379d58a38416eb84a9/lib/libharfbuzz.a to your qmake invocation.
Edit: it seems to be a knwonw behaviour of qt >= 5.12.1 : https://bugreports.qt.io/browse/QTBUG-72903. This feature has been reverted in 5.14.x and 5.15.x with https://github.com/qt/qtbase/commit/9864d2c6f3b628ca9f07a56b197e77bd43931cca

Using Qt Installer Framework to create my Application Installer

I want to create an installer for my Application. So, I have read about Qt Installer Framework and I tested the tutorial example and create the installer and everything work find with the example. But I have a doubt when I try to do the same process for my Application. When I compile the code a folder is created at the same level of my code:
MyApplication (my code)
build-MyApplication-Desktop_Qt_5_4_1_MinGW_32bit-Release (code compiled)
So my questions are:
What files of the compilation do I need to copy into the folder myinstaller/packages/vendor/ recommended by Qt Intaller Framework?
If I have dependencies of Qt like serialport, multimedia, and others, how do I insert these dependecies with Qt Installer Framework?
windeployqt.exe is what you want. Just run that on the command line and give it your executable as the argument. It will automatically copy in all the required Qt libraries and even provide the runtime redistributable installer. Then you can use the binarycreator to generate an installer.
You can put all the dependencies in myinstaller/packages/vendor/data, along with your exe. and eventual additional files. I recommended using i.e. dependency walker for finding all the required dependencies. Some of the binarycreator tutorials on qt are outdated; make sure you use the command
<location-of-ifw>\binarycreator.exe -t <location-of-ifw>\installerbase.exe -p <package_directory> -c <config_directory>\<config_file> <installer_name>
with the appropriate arguments.

Qt program deployment

In one of my programs I use QWebView to load and print reports made from HTML documents. So while deployment I copy these libraries, in additional to all other relevant Qt libraries:
Qt5WebKit.dll
Qt5WebKitWidgets.dll
Qt5PrintSupport.dll
plugins/printsupport/windowsprintersupport.dll
After testing on destination machine I've found that printing doesn't work. Thanks for Dependency Walker I've get all the missed libraries. Here is the list:
Qt5Multimedia.dll
Qt5Positioning.dll
Qt5MultimediaWidgets.dll
Qt5Qml.dll
Qt5Quick.dll
Qt5Sensors.dll
Qt5OpenGL.dll
Ok, I can understand why it wants Qt5Multimedia.dll. Browser can play sound etc. But QML! Why I need all these libraries related to QML?? I don't use neither OpenGL nor sensors or positioning. So it's just unnecessary in my case.
And so my question - is there way to deploy only libraries I need in actual fact? And get the program work of course.
I would suggest you to use windeployqt.exe.
From the docs:
The Windows deployment tool can be found in QTDIR/bin/windeployqt. It
is designed to automate the process of creating a deployable folder
that contains all libraries, QML imports, plugins, translations that
are required to run the application from that folder. This is used to
create the sandbox for Windows Runtime or an installation tree for
Windows desktop applications that can be easily bundled by an
installer.
This is how I do:
cd [my program dir]
mkdir RELEASE
cd RELEASE
copy ..\"progname.exe" .
set QTDIR=C:\Qt\Qt5.4.1\5.4\mingw491_32\bin
call %QTDIR%\qtenv2.bat
windeployqt --force "progname.exe"
You could adapt that for your need by changing [my program dir] to your application's folder (containing the .exe file), QTDIR to your Qt MinGW folder (that's what I use) and progname.exe with the name of your executable file.
It will create a release directory with your executable and the needed Qt libraries (.dll's, etc).

Configure Qt Creator to build statically (Ubuntu)

I'm trying to build a static application on Ubuntu (if it matters, Ubuntu running in a virtual machine in Windows), following the Qt documentation. Accordingly, I have build the libraries from source, using the configuration from the documentation:
./configure -static -prefix /path/to/Qt
There were no error messages from the build from source. I have tried setting the PATH variable in the build environment to the directory that contains my static build files. I've also tried specifying this path in the .pro file's LIBPATH variable. Nevertheless, whenever I build the application, a call to ldd shows that there are still dependencies to the Qt's dynamic libraries. I'm at a loss to understand how I need to configure Qt Creator to fix this.
You should download sources of interested Qt version, configure for static build and compile them yourself.

How to run a Qt application on a system where Qt is not installed?

I have made an application using QtWebKit, Qt4. I have the binary generated in Fedora 16. Now, I want to run that application on another PC (running some other Fedora version), where Qt is not installed. How can I package my Qt application so that it can run on a platform where Qt is not installed? Is there any command line utility as well as QtCreator utility to do so. I have tried "deploy all" command, but it didn't have any affect.
Create an Installer with the Qt Installer Framework and just supply all needed shared libraries (Win/OSX) or compile statically. Under Linux there is always the problem between system-wide libraries or bundled libraries. The documentation https://qt-project.org/doc/qt-5.0/qtdoc/deployment.html should give you a good start
Obviously, you need to have access to the qt libraries, which are exactly the same version that you used to compile your application.
There are two options :
link qt libraries statically
create a RPM package (see this how)
Also check Deploying Qt Applications.
Since you're deploying using rpm, to systems where Qt 4 rpms are available, you don't need to do anything besides simply adding a dependency on the qt to your rpm's specfile. The user installing your package using yum localinstall will get the Qt dependencies automatically installed. That's the correct way of doing it - it will keep your package size small.
Of course you need a separate rpm build for every fedora/centos major version out there, but that's almost always a requirement.
If your package needs newer Qt version than the one provided by the platform packages, you can still make a specific version dependency (say qt >= 4.7.0) and have a readme that indicates that newer packages can be obtained from a 3rd party repository (epel etc.)
For deployment under Linux I've used Bitrock Installer Tool.
The main thing before deploying is to check your dependencies. You can do that by using command:
ldd appName | grep libQt
After that you'll see list of dependencies. You'll have to set environment variable LD_LIBRARY_PATH to let linker know where're your libraries. To do that:
export LD_LIBRARY_PATH=.
. means current directory
And after that:
./appName $*
After that you'll be able to use your executable with Bitrock Installer Tool.

Resources