How to run a Qt application? - c++

I have been using Qt creator to make applications using the Qt libraries. I can run these applications by just clicking the play button, but I want to learn how to make applications run just by double clicking on a .exe. So how can I do this?

If you have built a 'release' version of your program, copy it and the following DLL's from qt\bin to a directory:
QtCore4.dll, QtGui4.dll and mingwm10.dll (if you are compiling with gcc and minGW).
If you are running a 'debug' build, you will need the debug versions of the Qt DLLs. They have the same name but with a 'd' at the end of the name.
There may be other Qt DLLs you will have to copy depending on Qt modules you are using in your program.
You can find out more from this page (Qt docs website) Deploying Qt Applications

I'm assuming you are running windows since you mention an .exe file extension. Look in the debug and/or release subdirectories of your project to find the produced binary. You can double-click on it to run the application. However, there are several DLL's that will be required. So, make sure they are in your PATH or copy them in the same directory. Dependency Walker is useful for finding out what you need.

Related

Qt C++ Missing DLLs

I created a simple notepad file using Qt.
The program does run when in Qt creator.
However, when I navigate to the debug folder, the created executable file does not run without DLLs.
I've read online that this is can happen and all that is required is that the respective DLLs be copied to the location of the exe file. However... the error messages identify DLLs that my machine does not have.
I get and error message for the following DLL files.
Qt5Cored.dll, Qt5Widgetsd.dll, QtPrintSupportd.dll
I do not have the DLLs above. I do however have the dll files below. Which do not have the added 'd' before the extension.
Qt5Core.dll, Qt5Widgets.dll, QtPrintSupport.dll
Any help provided would be much appreciated.
Thank you in advance!
First i can't think of any reason you would want to copy (preparing for an installer) the dependencies for the debug build of your application, the debug is not a build that you want to deploy, use the release build for deployment.
Now, that being said, you definitely have the dll's, otherwise your debug build won't run from Qt Creator, you are just not looking in the right path for those dlls.
The path where you find the dll is something like: C:\Qt\5.12.3\msvc2017_64\bin
notice that there can be many Qt versions installed and for different targets (example android), so the right way to find the dlls is: QT_INSTALL_PATH / QT_VERSION / COMPILER_VERSION _ARCHITECTURE / bin, so the sample path i provided is Qt version 5.12.3 build with Visual Studio 2017's compiler and it is a 64 bit build. In that path you will find the right dlls: Qt5Core.dll (the release build), Qt5Cored.dll (debug) and so on for all the Qt modules.
Side note: you most likely looked into the folder where Qt Creator .exe is located, there you will find only the Qt dlls that are needed for Qt Creator to work, you are not supposed to use those dlls to deploy your application (those might be built with a different compiler than what you are using and even cause crashes for your application, because of incompatible abi)

Qt Application (release) crashes when DLLs are added to its directory [duplicate]

I've written a couple of applications in QML (part of Qt 5). In a question that I've made before (https://softwareengineering.stackexchange.com/questions/213698/deploying-qt-based-app-on-mac-os-x), I found the solution for deploying my app on OS X (using the macdeployqt tool).
Deploying Qt4 apps on Windows was easy:
You compiled it in release mode.
You copied the necessary libraries (DLLs).
You tested and it worked.
Unfortunately, this approach did not work in Qt5 (I even included the platforms folder with the qwindows.dll file and it did not work). After some days of trying, I gave up and compiled a static version of Qt5.
Again, it did not work. The app works on a PC with Qt installed, but it crashes on "clean" PCs. As a side note, Windows 8/8.1 systems don't give a warning or a message notifying me about the app's crash. But in Windows 7 a message notifies me that the application crashed.
I've tried running Dependency Walker (depends.exe) and all libraries in the static build of my application seemed fine.
In Windows 8, I don't get any error. But after profiling the app in depends.exe, I get an access violation originating from QtGui.dll. The exact error is
Second chance exception 0xC0000005 (Access Violation) occurred in "QT5GUI.DLL" at address 0x61C2C000.
Is there something that I am missing (say an extra DLL or config file)?
Application information:
Written and compiled with Qt 5.2.1
Uses Quick/QML.
Uses the network module.
Uses the webkit module.
Uses the bluetooth module.
The QML files are written in Quick 2.2
Starting from Qt 5.2, there is windeployqt tool you can use. Just run it from command line to get help. But basic usage is, give it the .exe file, it will copy Qt dependencies to go with it.
You will want to use --qmldir option to let the tool know where your QML files are, so it can figure out the needed QML dependencies.
Note about testing: to make sure you have everything, test in computer with no Qt SDK, or temporarily rename the Qt directory. Otherwise the application might find missing files from there...
After some hours digging in the Qt Forums, I found out that I need to copy the "qml" folder (normally located in C:/Qt/5.2.1/qml) to the application's root directory. After doing so, both the dynamic and static versions of my application worked on vanilla systems.
Program directory (MinGW 4.8 32-bit, dynamic):
As hyde said, use the windeployqt tool (<qt path>\<version>\bin\windeployqt.exe) to copy the necessary files to your application's folder. After that, copy the required QML components from <qt path>\<version>\qml\ to your application's folder. The resulting folder should look similar to:
platforms (folder)
QtQuick (folder)
QtQuick.2 (folder)
Any other QML components that you need
app.exe
icudt51.dll
icuin51.dll
icuuc51.dll
libgcc_s_dw2-1.dll
libstdc++-6.dll
libwindthread-1.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Qml.dll
Qt5Quick.dll
Qt5Network.dll
Qt5Widgets.dll
Program directory (static)
Compile the application statically, then copy the required QML components from <qt path>\<version>\qml\ to your application's folder. The resulting folder should look similar to:
QtQuick (folder)
QtQuick.2 (folder)
Any other QML components that you need
app.exe
I think the cause for the crash was that the Qt5Gui.dll (dynamic and static) "tried" to load the QtQuick* folders during run time, but could not find them (thus crashing the application during load).

Qt application depends on dll's (which it doesn't need?)

I am compiling a Qt Webkit application and I understand webkitwidgets depends on a fair few dll's, however does every Webkit application required all these 20+ dll's to be shipped? Or am I doing something wrong here. This is every DLL needed to run my program.
CFF Explorer only shows these 10 DLLs:
The app comes to a hefty ~150mb so any way to reduce this? I wanted to compile statically however you cannot use webkit that way.
Open your Qt command promp.
mkdir installer
cd installer
Copy your generated exe file to this folder. And run:
windeployqt .
This command will copy all files you need. Use DependencyWalker for more info.
WARNING: some dlls are copied to be used in other OS version, so dont remove it, specially if you want that your app be compatible from Windows XP to Windows 10.

QT Deployment error

I am trying to deploy a QT5.4.1 appplication on Windows 7 - x86.
As always, everything is working fine on my machine, but not in the end user's machine.
When I try to run the app, it gives me the following error:
After searching on the internet, most solutions say that I need to add a platforms folders containing some dlls (qminimal, qoffscreen, etc) to the deployment package. I tried that with no success.
The funny thing is that I copied QT installation folder to the end user machine and deleted everything except this folder (C:\Qt\Qt5.4.1\5.4\msvc2012_opengl\plugins\platforms) and it works fine.
So, somehow my app is looking for the platforms folders in QT installation folder instead of the deployment package folder.
Does anyone know how to solve it?
EDIT:
I have managed to change all QT Dlls to the release version (without "d" sufix). However, when i compile my project I still get some vc++ dlls in debug mode. I checked all project configurations in both "linker" and "c/c++" sections and they all use "release" configurations. When I run the program, It gives me a "debug assertion failed". Why I am getting the debug versions of vc++ dlls?
Here is the dependency walker screenshot
The comments of Mezzo seem very relevant. We regularly deploy commercial Qt Windows applications. You could use dependency walker to find the dependencies or just double click on the executable and look at the Windows complaint about what dll's are missing. Just copy them to the deploy location, preferably with a qmake script.
The plugin dll's are more difficult to deal with. They do not show up as dependencies. The operating system could complain about their absence (dll's located in the subdir "platforms" for instance) or your application might just not use their functionality (dll's in the subdir "imageformats" for instance) without any complaint. To protect yourself against the latter case you have to test drive your application thoroughly.
Windows does not need a qt.conf file. Just create the subdirs "platforms", "imageformats", ... in the application dir and copy the plugin dll's there. As an example I show the full content of an (mingw) application dir that even when copied to a virtual machine runs without any problem.
Qt5Btc1.dll is our own dll.
I figure out what is wrong, although I don't have the solution yet. Even without the solution, I think this answer might be helpful.
My project output is a DLL that has a GUI made in QT.
Another program calls this DLL and during DLL_PROCESS_ATTACH a QT GUI is created.
According to the documentation, QT looks for the plugins in:
in the directory containing the application executable, i.e. > QCoreApplication::applicationDirPath() + QDir::separator() + "qt.conf"
That´s why the QCoreApplication::applicationDirPath() is not the deployment directory where the DLL is located, but the directory where the external program *.exe is running. I think QT is looking for the qt.conf file in this *.exe location
EDIT: there is nothing to do with debug or release versions

Deploying Qt application using QtMultimedia in release mode

I am developing a Qt 5.0 dekstop application using mingw47. I use QtMultimedia in this application to record and play audio. I have tested it for debug and it works. When I try to build it for release and run the executable file, I can't play the audio file that can normally be played in debug mode. I've added the following dlls before running the executable file:
D3D_Compiler_43.dll,
icudt49.dll,
icuin49.dll,
icuuc49.dll,
libEGL.dll,
libgcc_s_sjlj-1.dll,
libGLESv2.dll,
liblibmpeg2_plugin.dll,
libstdc++-6.dll,
libwinpthread-1.dll,
Qt5Core.dll,
Qt5Gui.dll,
Qt5Multimedia.dll,
Qt5Network.dll,
Qt5Widgets.dll,
Qt5Xml.dll,
plugins/platforms/(all dlls),
plugins/mediaservice/(all dlls),
plugins/playlistformats(all dlls)
What is probably wrong? Or what other dlls am I missing?
UPDATE: Use windeployqt.exe! It works really well.
http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool
The simplest way to use windeployqt is to add the bin directory of
your Qt installation (e.g. ) to the PATH variable and then
run:
windeployqt <path-to-app-binary>
While you are running your application in release mode (when it is working, ran from inside Qt Creator), execute depends.exe and point it at the application.
Make note of all the dlls that are referenced from your Qt folder.
Alternate way if you want to take more time with it:
You can figure it out by hand by trying to delete files because Windows won't let you delete a folder or a dll while it is in use. So you could go and make a back up of your Qt installation, and then run you application, make sure it has connected to all the dll's it is going to use, and then try to delete folders and files in your Qt installation. Windows won't let you delete files that are in use by your release.
Also here is how Windows resolves dll's if you wanted to know:
http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.80).aspx
EDIT: Also, you don't need to make the folder called plugins in your exe directory. It should be something like this:
Qt 4.x:
./myexe.exe
./QtCore.dll
./imageformats/qjpegd4.dll // Note: there isn't a "plugins" folder here
Qt 5.x: (take from here)
The executable ./plugandpaint.exe
The Basic Tools plugin ./plugins/pnp_basictools.dll
The ExtraFilters plugin ./plugins/pnp_extrafilters.dll
The Qt Windows platform plugin ./platforms/qwindows.dll
The Qt Core module ./Qt5Core.dll
The Qt GUI module ./Qt5Gui.dll
The Qt Widgets module ./Qt5Widgets.dll
Also run qDebug() << QApplication::libraryPaths(), and make note of paths that are searched for dlls on your computer.
Hope that helps.
All of the DLL's in your list that have their import libraries linked to the application will be automatically loaded by the OS. If any of them are missing you will get a dialog telling you which DLL it failed to load. The only ones that look like they might be loaded manually by the application are the plugins. Make sure you are telling the QT multimedia system to load the them. Also make sure you check the error codes returned by the multiamedia manager.
Given your recent comment that the audio plays in debug mode but not in release mode is a good indication you have put the plugin DLL's in the wrong place. When you launch your application from Explorer or the command line the plugins directory needs to be in the same directory as the application. Your directory structure should look something like below
c:\stackoverflow\myprogram.exe
c:\stackoverflow\plugins\platforms\(all dlls)
c:\stackoverflow\plugins\mediaservice\(all dlls)
c:\stackoverflow\plugins\playlistformats\(all dlls)
c:\stackoverflow\D3D_Compiler_43.dll
c:\stackoverflow\icudt49.dll
... other dll's here...
c:\stackoverflow\Qt5Network.dll
c:\stackoverflow\Qt5Widgets.dll
c:\stackoverflow\Qt5Xml.dll
I've found the answer. Now my application works. It can play audio file while running the executable file.
Although not listed in depends.exe, we should add the following dlls when using QMediaPlayer:
Qt5MultimediaWidgets
Qt5OpenGL
Here is the reference: https://bugreports.qt-project.org/browse/QTBUG-30172