How to deploy QT application with OpenSSL - qt

When I run the application from the directory that it was built in, there is no problem but when I try to run the application from another directory, after carrying the exe file in it, OpenSSL does not work.
I copied libcrypto-1_1-x64.dll and libssl-1_1-x64.dll files in the same directory, windeployqt takes care of the other dlls. What could be missing? If it's necessary, how do I make the configuration for the runtime?

OpenSSL libraries are precompiled with Qt via Qt Maintenance Tool. Because it's a C library it doesn't matter if is MSVC or MingW compiler. This little guide should work:
Install OpenSSL from Maintenance Tool.
Independently of your compiler, go to C:\Qt\Tools\OpenSSL\Win_x64\bin (if you have 64 bits application).
Copy libcrypto-1_1-x64.dll and libssl-1_1-x64.dll and paste in your release or debug application executable.

Related

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

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.

mingwm10.dll missing in the bin folder

I was trying to create a exe file of my Qt project.
I found this post: How to create executable file for a Qt Application?
and realised that i dont have a mingwm10.dll file in that directory.
Are there any other ways of creating a exe file or any other location where mingwm10.dll might be located?
I am using qt 5.6.
mingwm10.dll is a runtime file for the MinGW.org toolchain. Qt moved towards a MinGW-w64-based toolchain (which is essentially an expanded and newer implementation of the Win32 headers and import libraries), which doesn't have this runtime dependency. Ignore it, you don't need it. You might need the libgcc and libstdc++ DLLs though, but that's the same with any (non-statically built) toolchain.
Note you can use the windeployqt utility to automatically copy over all runtime depencies of an executable. You can enable it by adding windeployqt to CONFIG if you're using qmake, or you could just run it yourself:
windeployqt my_app.exe
This command will copy all DLLs (including the Qt platform plugins etc.) so that the application can be run by e.g. double-clicking, instead of only in the specific environment of an IDE.

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

standalone exe in Qt

I want to make a standalone .exe file in Qt msvc 2010 5. I change the mode to "release" and build my project and I copy the .exe file in release/debug folder to bin directory in Qt directory and then I copy all the bin folder. it works properly in my computer, but when I move the bin folder to other computers the .exe file doesn't work. I installed visual c++ 2010 redistributable package in the other computer but still it doesn't work. what should I do?
The answer is most likely that the other machine doesn't have Qt installed. If you want a wholly standalone Qt app on Windows (statically linked), check this out: http://qt-project.org/wiki/Build_Standalone_Qt_Application_for_Windows
Some quick build instructions -
Make sure you have python installed and in your path Get the Qt
source code
(http://download.qt-project.org/official_releases/qt/5.1/5.1.1/single/qt-everywhere-opensource-src-5.1.1.zip)
unzip the zip file and open a Visual Studio command prompt in that
directory
execute configure -static -release -no-audio-backend
-opengl desktop -opensource -confirm-license
execute nmake (this will compile all of Qt and will take a while depending on your processing power)
add CONFIG+=static to your .pro file call qmake from the build of qt you
just made and then run nmake on your project. You'll then get a
statically linked binary. You'll know because even a very small
program will be > 5MB in size.

Run .EXE without Qt

[ Solution ]
I want to run my app created with QtSDK on a machine that does not have Qt installed.
I tried to copy the DLL's from the BIN folder to the release of my project, but it did not work.
I tried the following:
I copy all dll's folder d:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin
And pasted it in the folder of my project: d:\projects\mybrowser\mybrowser-build-Desktop_Qt_5_0_1_MinGW_32bit-Release\release
and send it to another computer without Qt
In computer without Qt, I installed vcredist_sp1_x86.exe and tried to run my application browsertest.exe
The following error occurred:
microsoft visual c++ runtime library: this application has requested
the runtime to terminate it in an unusual way
Q: What I really want to know:
How do I run an application built in Qt on other computers (Windows) without Qt installed?
Details:
Qt5.0.1 32bit
mingw 4.7 32bit
QtCreator 2.6.2
Windows 7 64bit.
Intel i5
Folders:
D:\Qt\Qt5.0.1\5.0.1\mingw47_32
D:\Qt\Qt5.0.1\Tools\MinGW
Qt/Mingw:
D:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin\qmake.exe
d:\Qt\Qt5.0.1\Tools\MinGW\bin\gcc.exe
File .pro:
QT += webkitwidgets network core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = browsertest
TEMPLATE = app
RC_FILE = browser.rc
SOURCES += main.cpp\
mybrowser.cpp
HEADERS += mybrowser.h
FORMS += mybrowser.ui
If any information you missed, please let me know.
grateful
To distribute your application you need to copy the DLLs (only the DLLs necessary).
Copy the DLLs necessary from
<DRIVE>:\Qt\Qt<Version_qt>\<Version_qt>\mingw<Version_mingw>\ or <DRIVE>:\Qt\Qt<Version_qt>\<Version_qt>\mingw<Version_mingw>\bin\
eg.: C:\Qt\Qt5.2.0\5.2.0\mingw48_32\ or C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin
Paste the folder of your application.
Then copy the folders inside of <DRIVE>:\Qt\Qt<Version_qt>\<Version_qt>\mingw<Version_mingw>\plugins
eg.: C:\Qt\Qt5.2.0\5.2.0\mingw48_32\plugins
Paste the folders of your application.
Note: In this example (below), it was necessary to copy DLLs from different places and remove the Debug DLLs (used only to compile in Debug).
Note that the debug dlls end with "d.dll", for example: Qt5Core.dll and Qt5Cored.dll or Qt5Concurrent.dll and Qt5Concurrentd.dll, the ending with "d.dll" should not be copied.
The structure should look something like this (example):
c:\project\app.exe (your app created in Qt)
c:\project\Qt5Core.dll (dll from qt/mingw folder or qt/mingw/bin)
c:\project\platforms (folder from qt/mingw/plugins folder)
c:\project\platforms\qminimal.dll (dll from qt/mingw/plugins/platforms folder)
Only some DLLs the mingw will be needed, so I recommend using the Dependency Walker 2.2
The result should look like this (not all dlls are needed, this can vary by project type):
Thanks to:
+1 for #MartinBeckett, showed me the program to find the DLLs required.
+1 for #WouterHuysentruit, thanks to the application I indicated, I discovered that the contents of the mingw\plugins folder should go straight into the application folder.
#WouterHuysentruit I would consider your answer as correct, but you just said, so I put a simpler explanation. Thanks anyway.
"microsoft visual c++ runtime library: this application has requested the runtime to terminate it in an unusual way"
That's either an ordinary bug, or sometimes a mix of incompatible dlls
Use the (free) depends program on your exe to check which dlls it actually uses - it probably isn't linking all of Qt
Some Qt libs are loaded at runtime from a plugins folder, mostly image formats and database connections - but they woudln't give this error
windeployqt (delivered with QT 5.2+) should do (most?) of the work

Resources