How to run a Qt Program without Qt itself being installed? - c++

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

Related

Why have .a files been installed in Windows with Qt online installer?

I installed Qt 6.3.1 libraries pre-built with MinGW 11.2.0 64-bit using the online installer. The application crashes without entering the main function when I use any of Qt libraries in the Qt Creator while there is no problem if I use only C++ standart library. I guess the problem is in linking. Because I realized that there are .a files in the folder C:\Qt-mingw\6.3.1\mingw_64\lib, even though I am using Windows 10. Why are .a files installed instead of .lib files? How to solve this issue?
Here are the the selections that I made when installing Qt libraries using the online installer:
After learning that the problem may be due to duplication of some library from here, I saw using dependency walker that my program uses libstdc++-6.dll in system32 instead of qt-mingw installation. So the problem solved when I copied that dll into my app's folder. But I wonder how to solve this by changing the path without copying libstdc++-6.dll into app's folder. Because even though I put qt-mingw bin folder at the very beginning in system path, app uses still the one in system32.

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

Qt application deployment

What are the necessary dll files to deploy an application using Qt? By necessary I mean those who are common to all applications, not the entire dll folder. Are msvr120.dll and msvc120.dll necessary too? Thanks to further answers.
Dependency Walker is your best friend in this case.
In short, it depends on how many Qt modules you used in your project.
Check your project file, for example:
QT += core gui script
Then you will need
QtCore4.dll / Qt5Core.dll (QtCored4.dll / Qt5Cored.dll for debug)
QtGui4.dll / Qt5Gui.dll
QtScript4.dll / Qt5Script.dll
which can be found in bin folder under Qt directory.
As for msvr120.dll and msvc120.dll. You may distribute them as well, in case your user's Windows system doesn't have them (e.g. older version like Windows XP, but I am not sure whether those dlls work in older version of Windows)
Windows Qt installations include windeployqt.exe deployment helper which will copy Qt(and MinGW if you use it) library .dlls. Check your Qt installation directory, it's in same as qmake.exe
Basic usage from cmd: (Replace --debug with --release for release builds)
mkdir Deploy
copy /y /path/to/exe Deploy
cd Deploy
windeployqt.exe --debug Prog.exe
Aside from required .dll files it will also put optional plugins, translation files and configuration files for everything. You can later remove non needed files and upx the rest.
Additional info here: Qt for Windows - Deployment (thanks peppe for link). windeployqt.exe is mentioned at the bottom of the page.
Note: It can't deploy MSVC runtime libraries. You need a redistrubutable for them, so you can silently install them with your installer.

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.

How to create executable file for a Qt Application?

I've been searching on the internet for some useful and clear information about this, it's annoying that such a trivial thing is so hard to do.
What I need is to create an executable file for my Qt project, in order to run it in other computers. My project runs nicely in the Qt Creator, but when I try to run the executable created in the release folder I get errors about some dll missing, and though I have put all of them in the same directory of my .exe I now got some errors about entrypoints in procedures inside the dll (QtCore4.dll).
The solution looks like to be a static linking, I've found many information about it, but none of them really helped me. Here is what I have tried so far:
Using the executable created in the release folder as I said above.
Static Linking, following this tutorial (and many others, all almost the same thing): http://doc.qt.io/qt-4.8/deployment-windows.html but I get the following error during the "configure -static": NMAKE : fatal error U1077: '"c:\Arquivos de programas\Microsoft Visual Studio 9.
0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
Building qmake failed, return code 2
For that I couldn't find any solution, so here I am, just trying to create an executable file for my Qt project, hope you guys can give me some light here.
Basically you have to look for mingw subfolder deep into qt tree, where qt utilities reside, and copy needed dll's.
These are the steps I follow, based upon QT 4.7.4, for packaging the application with correct shared libraries.
Let's say you've installed QT under c:\qtsdk
Open your project, and compile it in release mode.
Go to this directory: C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin -- it contains all shared libraries. Debug libraries end with a "d" -- frex, QtCore.dll is release version, while QtCoreD.dll is debug version
Copy at least these files into your release directory (where your .exe lies)
mingwm10.dll
libgcc_s_dw2-1.dll
QtCore4.dll
QtGui4.dll
I just built, tested and deployed a dummy project this way.
Do these steps:
1- Open qt command-line window.
2- Go to the directory which .exe file exists (using cd command).
3- Run windeployqt.exe --quick . command
4- Run your exe file and enjoy it!
This video is great
Here is what I did and I got it to work after some time;after making sure that your program builds inside Qtcreator,go to the directory that contains your exe and double click on it.(I'm using windows and don't know if it is the same on other platforms).A window should popup telling you which .dll is missing.Go to the directory where Qt is installed and type the exact name in the search bar(top-right in Windows 7) and the dll should show up in search results.Right click and choose open file location.Copy the file where your exe is located .Double click on the exe again.If another .dll is missing repeat the same thing until none is missing.In the end your program should run.
Hope this helps.
So you downloaded Qt SDK and you want to link Qt libraries statically into you application, right?
First of all, if you link statically, you don't need any Qt*.dll to be present anywhere because it is built into the application. So that alone means that your application is built using dynamic linking.
From my experience, that safest way to get it all working is:
Download Qt sources, build and install them with nmake ( using Visual Studio Command Prompt from Menu Start -> Application -> Visual Studio 2008 ). Just remember that the size of the statically linked application is dependent on the size of the *.libs and these are dependent on the pre-build configuration, for example, you can minimize the size of you application by turning off some features ( this is an example config for MacOSX, just watch out for the ones specific for Windows and add proper plaftorm - see configure.exe --help for details ):
./configure -arch x86 -platform macx-g++ --universal -cocoa -debug-and-release -opensource -static -fast -no-accessibility -no-sql-sqlite -no-qt3support -no-opengl -no-openvg -qt-zlib -no-gif -no-libmng -qt-libmng -no-libtiff -qt-libjpeg -no-3dnow -sse -no-sse2 -no-openssl -no-dbus -no-phonon -no-multimedia -no-audio-backend -webkit -no-script -no-scripttools -no-declarative -nomake demos -nomake examples -no-exceptions -no-accessibility -confirm-license
Install, setup and use Visual Studio Add-In for you Qt project (here ).
Good Luck! :)
I share with you my solution. On my qt creator 4.2.1, I did these steps:
1) - I clicked on release and it generated a folder in my project directory like that: C:\Users\Samir\Documents\Qt-Projects\build-Calculator-Desktop_Qt_5_8_0_MinGW_32bit-Release.
2) - I opened the terminal qt 5.8 for desktop and I navigated to my project directory where the .exe located.
3) - Finally, I ran the command line windeployqt.exe --quick .. This command allowed me to generate the libraries which were missing.
And now everything works fine!