I wrote a Qt application on Linux that compiles and runs. When I try to compile the code on Qt Creator on Windows I can't run the executable.
The application will only run from within Qt Creator. Does this have something to do with dependencies? I know for static builds, I need to build a static version of Qt Creator. But aside from doing that, what else would I need to do for the program to run?
You can place the required QT dlls, QtCore, QtGui, etc, in your .exe's folder.
You should be able to find these dll's in your QT install folder.
If you're not sure which dll's you need - you may want to try out Dependency Walker
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 msvcr100.dll and msvcp100.dll in case you are using MSVS2010. 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".
Related
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)
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).
When I run my application in other machine and if i rename the Qt directory i'm getting the "This application failed to start because it could not find or load the Qt platform plugin "windows". Reinstalling the application may fix this problem."
Here's the layout of the folder holding the application:
app.exe
icudt53.dll
icuin53.dll
icuuc53.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
msvcp110.dll
platforms/qwindows.dll
Is there any possibility to force the seek qwindows.dll for directory of my application instead of the QT directory?
use windeployqt:
go to your QT installation folder, something like this: C:\QT\5.5\msvc2013\bin there is an .exe located here called windeployqt start your cmd from here. (ctrl+shift+rightclick). Then type the following:
windeploy [full path to your release map]
Qt install directory should not be in your PATH environment. Then renaming the Qt dir is not necessary (in contrast to OSX). During development you can run your application from inside Qt Creator.
If you run your application outside Qt Creator, for instance by double clicking on it in explorer, Windows will also automatically include in its search path the application dir and as a matter of fact it is the first location it will look. If it cannot find the dll there, or if it is the wrong version (like 32/64bit) it will try to find it somewhere else. There is no need to set or load library paths. Use dependency walker to find out what dll's you need. Copy them from the Qt Install dir or extract them from the Microsoft vc-redistributable exe in case a msvc dll is needed (I think you are missing the msvcr dll). All this dll copying should be preferably done with a qmake script. Which plugin Qt dll your application need is a matter of trial and error. For some missing plugin dll's the OS will issue a warning when running the appplication.
You could follow Pim's advice by using windeployqt. We prefer to control ourselves what dll's are going to be deployed.
Your location of the plugin platforms qwindows.dll is exactly correct. The application does not load the plugin dll's but the Qt dll's load the plugin dll's and these Qt dll's know exactly where to expect and find them. The only reason I can imagine that you have problems is that your app loads the wrong Qt dll and that dll cannot find the platforms dll. Do not forget that many other multi-platform applications use Qt as well. They might have dumped Qt dll's in the system32 directory or they might expose them by adding their application dir to the PATH environment. Welcome to the dll hell.
There is a simple approach to fight the dll hell: remove (and restore) from your app dir the dll's one by one and each time double click your app. If Windows does not complain about missing exactly that dll you just removed that dll was not the correct version. If this still does not help you are probably missing out another Qt dll your application is using.
I solved the problem by setting the path in the code.
TCHAR path[_MAX_PATH+1];
GetModuleFileName(GetModuleHandle("myApp.dll"),path,sizeof(path)/sizeof(path[0]));
std::string runningFolder = ExtractFileDir( path );
QStringList paths;
paths.append(runningFolder.c_str());
QCoreApplication::setLibraryPaths(paths);
app = static_cast <QApplication *> (QApplication::instance());
if ( app == NULL )
{
int argc = 0;
app = new QApplication( argc, NULL );
}
In some cases 'platforms' must also contains qminimal.dll:
https://stackoverflow.com/a/14144077/4149835
platforms/qwindows.dll platforms/qminimal.dll
I built my app as normal exe and run windeployqt on it. I got long list of files in folder with exe.
files:
./
D3Dcompiler_47.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Svg.dll
Qt5Widgets.dll
WLedPlugin.exe
accessible
files.txt
iconengines
icudt52.dll
icuin52.dll
icuuc52.dll
imageformats
libEGL.dll
libGLESv2.dll
platforms
qt_cs.qm
qt_de.qm
qt_fi.qm
qt_hu.qm
qt_it.qm
qt_ja.qm
qt_ru.qm
qt_sk.qm
qt_uk.qm
./accessible:
qtaccessiblewidgets.dll
./iconengines:
qsvgicon.dll
./imageformats:
qdds.dll
qgif.dll
qicns.dll
qico.dll
qjp2.dll
qjpeg.dll
qmng.dll
qsvg.dll
qtga.dll
qtiff.dll
qwbmp.dll
qwebp.dll
./platforms:
qwindows.dll
then I compiled app as dll and put it into folder with proper program. (I'm developing plugin for Keil IDE). DLL is seen well, but when part of code
with QApplication launches, then it can't find windows plugin.
So as you see qwindows.dll is in proper folder as libEGL and libGLESv2 are too and it still cannot see windows plugin.
I'am using msvc compiler x86 and Qt 5.3 version.
Some workaround found -> I simply threw msvc off and used mingw instead. It simply wroked.
You need to place qt.conf near your .exe, or in resources to :qt/etc/qt.conf
[Paths]
Prefix=.
Plugins=.
Ok i guess now i know a bit more what was the problem about.
I had folder with Keil application and folder with my dll plugin.
Windows check for called dll's dependencies in application's that called
dll directory in first, not in dll directory. Dll directory is in lower position.
Of course sooner or later windows should finally get to the dll's folder, but on some machines it didn't. Moving dependencies from DLL's directory to application's directory helped and is working well for the time being. Thanks all for help! :)
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.