What dlls do i need to distribute my Qt application? - c++

I built a Qt app that I'd like to distribute to a few people.
On a computer with QtCreator installed, I can get it to run by placing a bunch of Qt dlls (I inserted the ones it complained about) inside the same folder as the executable. But if I uninstall Qt or try it on a computer without Qt, the executable does nothing. No error, just no window or process when I run it.
Here's what I've tried:
-put every dll from the qt folder with the executable. No effect.
-run it with dependency walker. I'm not entirely sure I'm using it right but, with Qt uninstalled and the necessary dlls with the executable, it doesn't give me any missing or invalid modules. Just a couple of red lines in the logger after profiling like:
GetProcAddress(0x75AC0000 [KERNEL32.DLL], "SetDefaultDllDirectories") called from "MSVCR110.DLL" at address 0x6AC0FD4F and returned NULL. Error: The specified procedure could not be found (127).
and
GetProcAddress(0x75AC0000 [KERNEL32.DLL], "GetCurrentPackageId") called from "MSVCR110.DLL" at address 0x6AC0FDFA and returned NULL. Error: The specified procedure could not be found (127).
Nothing related to qt that I can tell.
I'm testing on a virtual machine (trying to simulate a non-dev machine) with 32bit windows 7. MSVC redist 2010 and 2012 are installed.
It's Qt 5.1.0 MSCV2012-32bit. And I have the same problems with the 64bit version (I haven't used dependency walker with the 64 bit version though).
Is there some step I'm missing?

I have found you need to add a sub directory with some of the plug in dlls found in the plugin subdirectory of the install folder (where you find the include and bin folder)
in particular the platforms subdirectory and the qminimale.dll and windows.dll in it are needed for a gui
edit: to be clear add a subdirectory platforms to the directory with the exe and add the qminimale.dll and windows.dll to it

Related

Building Qt static, can't find MinGW

I'm trying to build a static version of Qt, so I could make a .exe file of my project.
I have found this tutorial, and am using the script made by the tutorial author. When I try to run the script, my PowerShell gives me this>
Building static Qt version 5.3.1
ERROR: MinGW environment not found, no Qt prebuilt version?
Press Enter to continue...:
This is impossible. I know this because I already had made projects with Qt5 and built them with my MinGW compiler.
Some additional info:
MinGW is located:
C:/Qt/Tools/mingw491_32 (/bin/gcc.exe)
When I open the script, theres this line>
#Search all instances of gcc.exe from C:\Qt prebuilt environment.
$GccList = #(Get-ChildItem -Path C:\Qt\*\Tools\mingw*\bin\gcc.exe | ForEach-Object FullName | Sort-Object)
So, to me it looks like the gcc should be found by the script.
Anyone have any ideas as to what is happening here?
Thanks.
Replace
C:\Qt\*\Tools\mingw*\bin\gcc.exe
with
C:\Qt\Tools\mingw*\bin\gcc.exe
Not exactly the answer to your question but probably the solution for your problem.
There is no need to make Qt static for creating an executable of your sources. The static option is more appropriate for embedded system without OS, or with a very thin OS below. I can't imagine, it would make sense on windows.
Build a release version, copy your exe and all required dlls of Qt and mingw to one directory and copy this directory to any windows pc. It should work.
For checking, which dlls are required, use depends-tool
For providing your exe in a more professional way, create an installer. I'd recommend Inno Setup, which is very easy to use.
In case you want to copy the dlls use windeployqt, its very simple than using dependency walker. This will copy all the dlls for you to a given folder...
Copy <MyApp.exe> to a folder say <MyAppPackage>
cd to <MyAppPackage>
C:\Qt\Qt5.7.0\5.7\mingw53_32\bin\windeployqt.exe MyApp.exe
All the dlls will be copied to <MyAppPackage> folder.
It helped me:
The path that reads " C:\Qt*\Tools\mingw*\bin\gcc.exe" needed to be changed to " C:\Qt\Tools\mingw*\bin\gcc.exe" on my (Windows 10) system.
https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW

How to run a Qt Program without Qt itself being installed?

I have written a program with Qt5.3.1 and run it on my development machine where it works fine. I copied all necessary .dll files into the folder where my .exe is. These are:
Qt5Widgets.dll
Qt5Network.dll
Qt5Gui.dll
Qt5Core.dll
icudt51.dll
icuin51.dll
icuuc51.dll
libgcc_s_dw2-1.dll
libwinpthread-1.dll
libstdc++-6.dll
Now I want to run that program on a machine that has no Qt installed. How do I do that? It shouldn't be necessary for users to install an IDE just to use a program, right?
Details of the development machine where it works:
Windows 8
Qt 5.3.1
The deploying platform is:
Windows Vista
No Qt installed but all necessary .dlls are in place
Errors I get are first:
This application failed to start because it could not find or load the Qt platform plugin "windows".
Reinstalling the application may fix this problem.
Next error message is:
This application requested the Runtime to terminate in an unusual way. Please contact support.
Then the program crashes. But if I install Qt5.3.1 it works. So it has something to do with files in the c:/Qt directory
This application failed to start because it could not find or load the Qt platform plugin "windows".
For this problem, you should copy the plugin {QTSDK}/plugins/platforms/qwindows.dll to {YOUR_EXE_DIR}/platforms/qwindows.dll.
The short answer is you either need to do a static build, or you need to redistribute the Qt shared library DLLs. If you're looking for a smaller file size static builds are often better, but there may be legal implications with this approach if you're using Qt5 under a LGPL license. I'm not a lawyer, but you can read about LGPL linking rules in LGPL section 4.1.
The long answer is you should read the general Qt5 deployment guide and the Qt5 for Windows deployment guide. These go into quite a bit of detail.
A better solution is to use the Qt SDK application "windeployqt". It is used to copy all the required dlls and plugins to your application folder based on target platform. You can then run that on another computer. Here is the documentation: https://doc.qt.io/Qt-5/windows-deployment.html.
For example, if your executable was built using mingw53_32 and your executable is in "C:\example_qtapp":
QT_INSTALL_DIR\minqw53_32\bin\windeployqt.exe c:\example_qtapp
I have encountered this problem as well,
In your Qt Directory, with the proper Qt version
C:\Qt\Qt5.2.1\5.2.1\mingw48_32\plugins\platforms\
copy qwindows.dll into a new folder that lives next to your executable, such that your list would be
Qt5Widgets.dll
Qt5Network.dll
Qt5Gui.dll
Qt5Core.dll
icudt51.dll
icuin51.dll
icuuc51.dll
libgcc_s_dw2-1.dll
libwinpthread-1.dll
libstdc++-6.dll
platforms/qwindows.dll
You should place Qt DLLs along the release version of your executable. These are Qt5Core.dll, Qt5Gui.dll and possibly the ones for other modules that you have used. These dll files are in your installed Qt Directory in bin folder. You should also place LIBGCC_S_DW2-1.DLL, MINGWM10.DLL and LIBSTDC++-6.dll in case you are using MinGW.
If you are using plugins you should place their dll in a folder named plugins beside your exe. In case of using icons and images you should ship their dlls like qico.dll and qsvg.dll in a folder named imageformats.
if Qt dlls are there, they it should work. My guess is that you are missing the run time libraries/dlls of your IDE. For example, if you are using Visual Studio 2010 as your IDE, then you need to install VS2010 Redistributable x86/x64 link depends on your architecture.
You should also copy {QTSDK}/plugins to directory where you executable located. Then create qt.conf in the same place (with executable) with the following content:
[Paths]
Plugins=plugins
Thеn, run your program. I did the same on linux.
In your application folder hold down SHIFT key and right click from mouse.
You will see - Open command window here
Click Open command window here
TYPE windeployqt.exe app_name.exe --parameters and HIT ENTER
Example:
windeployqt.exe APP_NAME.EXE --release --no-translations --no-system-d3d-compiler --no-compiler-runtime --no-angle --no-opengl-sw

QMYSQL driver not loaded on Windows

I am trying to implement a database system in my Qt application. For this purpose, I am trying to use MySQL (with the related QMYSQL driver). My class connection-function is written below.
Assuming that connection is defined as a private class member:
private:
QSqlDatabase connection;
we have the following:
database::database() : connection() {
this->connection.addDatabase("QMYSQL");
this->connection.setHostName(p.database->server_addr);
this->connection.setUserName(p.database->username);
this->connection.setPassword(p.database->password);
this->connection.setDatabaseName(p.database->database_name);
if (!connection.open())
this->error = this->connection.lastError().text();
else this->error = "";
}
I get database::error with the value Driver not loaded Driver not loaded (yes, it's written twice). I've seen here on Stack Overflow that I have to put the driver libraries in my application's path. I've done this and nothing happened. Below is a screenshot of the Qt libraries that are in my path.
EDIT
After calling QSqlDatabase::drivers(), I found out that I have the drivers available. Below is the output ( int the show-more section of the message-box).
For mingw and Windows: Download the C (not c++) connector from: https://dev.mysql.com/downloads/connector/c/,
then copy the library: libmysql.dll, to the folder: D:\Qt\5.5\mingw492_32\bin.
This should solve the problem for the not loaded driver.
1) I assume that you already compiled your qsqlmysql dll. You should have the qmyssql.dll in the plugins/sqldrivers directory relative to your binary path of your executable.
2) You should also be careful not to mix release and debug dlls (the ones with the d at the end).
3) The static method addDatabase should be used this way: this->connection = QSqlDatabase::addDatabase(DRIVER, NAME);
4) Another point: The reason you get the error "twice" (you actually just get two errors combined) is that connection.lastError().text() results a combined error message (appended) from the driver and from the connection attempt (see the API more more information about the differences).
5) When i took a closer look at your libs i could not see the non-debug version of libmysql.dll. If you run in release mode you must use the release library since the runtime will look for libmysql.dll and not libmysqld.dll. This will give you this error.
In addition to #OnWhenReady's answer, I run the DependencyWalker on the qsqlmysql.dll and found that there were missing some dependencies.
IEShims.dll
I copied it in my path and now it's working!
As a tip: run DependecyWalker for this kind of libraries, because, as it's written in the Qt Documentation, QMYSQL driver libraries won't give errors (won't show them).
Please see the link for QT5:
http://seppemagiels.com/blog/create-mysql-driver-qt5-windows
=> qsqlmysql.dll and libmysql.dll (and libmysql.lib, if your installation of MySQL has it) are needed
And the link for QT4:
http://seppemagiels.com/blog/create-mysql-driver-qt-windows
=> libqsqlmysql4.a and qsqlmysql4.dll and libmysql.dll (and libmysql.lib, if your installation of MySQL has it) are needed
I use msys2 with its qt5 package mingw64/mingw-w64-x86_64-qt5 (5.8.0-3) and looking at the plugins/sqldrivers/qsqlmysql.dll with the Dependency Walker reveled dependency on the mariadb.dll, so I installed the mariadb client package:
pacman -S mingw64/mingw-w64-x86_64-libmariadbclient
and the dll appeared in /mingw64/bin/mariadb.dll, so I just copied the dll next to my app's exe file and it suddenly worked.
Even if you don't use msys2, you should still look at your qsqlmysql.dll with Dependency Walker and provide the missing dlls to your app. You can install MariaDB or MySQL connectors and just copy the dlls from the installed path.
I have encountered this problem many times. If you are in
LINUX: You need to build it. You need to first install MySQL server then MySQL Client from package manager. then follow instructions in Qt Documentation website Here. Which is basically these commands:
cd $QTDIR/qtbase/src/plugins/sqldrivers/mysql
make install
and after the build process finishes, generated plugin will in $QTDIR/qtbase/src/plugins/sqldrivers/ i guess.
WINDOWS: No need to build. Install MySQL and after that you can
Install MySQL Connector C (.msi file) and add installation destination folder to PATH.
or download the zip file and extract it in somewhere that your application can find.
also, if you have done all above and still doesn't work, you need to install Visual C++ Runtime Libraries. I had this problem in XP and Dependency Walker didn't show any missing or incompatible .dll file and after installing those runtime libs my problem was solved. Where you can find them packed and ready? Here
Before you test your app, its a good idea to reboot so those changes in PATH and ... can take effect.

QT missing dll after deploy

I've copied all of the dlls from QT that were required, and my application works fine on my Windows server machine.
However when trying to run it on a Windows 7 box i get the following message:
This application failed to start because it could not find or load he
Qt platform plugin "windows".
Reinstallning the application may fix this problem.
Any ideas what I'm missing here?
I'd scratched my head over this some time ago. It turned out that this was caused not by missing qwindows.dll, but rather one of libEGL.dll or libGLESv2.dll. This was tricky, because dependency walker does not show those libs as direct dependencies.
If you want to test on your dev machine, whether your app has all required libs, fire up console issue SET PATH=, cd to your app directory and run it.
This is complete list of dlls that my app is using (Qt 5.2 / QtQuick app only, rest is C++). QtQuick is nice but the size of Qt dependencies is a bit scary:
icu*.dll - depending on whether you've compiled with ICU
libEGL.dll
libGLESv2.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5Qml.dll
Qt5Quick.dll
Qt5Widgets.dll
Widely used solution is put all necessary libraris in the folder of application.
What are libraries application need?
Run application and see error message:
The program can't start because <Library name> is missing from your computer.
Try reinstalling the program to fix this problem
Library set is depended from Qt version. Run several times application and each time copy required lib you found what is neeeded for application.
In my case (Qt 5.2.1) there are
icudt51.dll,
icuin51.dll,
icuuc51.dll,
libgcc_s_dw2-1.dll,
libstdc++-6.dll,
libwinpthread-1.dll,
Qt5Core.dll,
Qt5Gui.dll,
Qt5Widgets.dll.
All libs you can found in your Qt install folder. But don't use libraries from Tools\QtCreator folder, because QtCreator has another version of these libraries!
In case of error:
This application failed to start because it could not find or load he Qt platform plugin windows. Reinstallning the application may fix this problem.
You should create folder platforms and copy qwindows.dll into it.
If you still got error you should create qt.conf file in application's folder with content:
[Paths]
Plugins=plugins
This solution is described in https://qt-project.org/forums/viewthread/37265
More information about qt.conf you can find at http://qt-project.org/doc/qt-5/qt-conf.html
In latest versions of Qt you can find deploy tool (since 5.2). This tool find necessary libraries for application and copy into application folder. You can run it something like this:
call c:\Qt\QtX.Y.Z\X.Y.Z\mingw48_32\bin\qtenv2.bat
cd /d "c:\path\to\your\application\folder"
windeployqt.exe your_application.exe
Generally it works well. But I notice that some libraries are not copied, but you can found by method is descibed at beggining of post. More useful information you can find at
http://qt-project.org/doc/qt-5/windows-deployment.html
In rare cases yo can got this error if some library is missing but not appear in error message above. Example: Qt 5.1.1: Application failed to start because platform plugin "windows" is missing
I wasn't in this situation, so I can't tell more.

Compiling a static QT application on Windows

I am new to QT and I am enjoying the experience except for the fact I cannot manage to statically link the QT library to the output binaries. When I run the output file outside of the QT directory, I get The program can't start beacuse QtCored4.dll is missing. Obviously QT is dynamically linking their libraries and requesting a .dll I do not have. Is there a way to statically compile QT's libraries into a static binary so none of QT's dlls are required? I ask this because I am already up to 11 .dlls for my project, and I would really like to cut down the amount of files that have to be distributed with my software. Size is not a problem for me. Thanks.
I have tried adding CONFIG += static to the .pro file, but to no avail.
First off, you can't statically link Qt unless you've bought a commercial license. To do so would put you in violation of the LGPL license under which the non-commercial version is distributed. I feel your pain, I've got many, many DLL's to go with my software.
Thankfully, you probably do have the DLL's if you used the installer: you don't need to build from source, that should have been done automatically. You'll find them in Qt\Version\bin, where Qt is the directory you installed Qt, and version is the version of Qt you installed. For example, mine is found in G:\Libraries\Qt\4.7.1\bin.
I did, however, have some issues with not having one of the DLL's built - one for working with OpenGL - and performed a rebuild to do so. I've also done so when I've switched versions of Visual Studio. I think it's handy to be able to do so, it's easy, Open a terminal in the Qt directory, and execute:
configure.exe -platform XXX'
Where XXX denotes the type of build you want to perform. Valid options include win32-msvc2005, win32-msvc2008, win32-msvc2010. So I use:
configure.exe -platform win32-msvc2010'
Other options are detailed here. These instructions apply if you've downloaded the source code, however you might have to add the current directory to the path variable like so:
set PATH=%cd%\bin;%PATH%
The whole procedure should take about an hour.
You need to download the source packet of QT and compile it. It takes some time but is not really complicated.
Download and unzip QT source
Start a compiler shell (Visual Studio or mingw)
Execute configure in the QT source directory - add a flag for static compile here
execute make (Visual Studio nmake)
Wait some hours depending on the speed of your machine