How to compile a standalone with QT Creator on Windows? - c++

I created a Qt App with Qt Creator. I want to send the stand-alone executable to a friend, but he can't execute the file. His error was that he is missing a lot of DLLs.
How can I compile a truly standalone executable? One such that my friend doesn't have to install any dlls or frameworks to execute this program?
I'm using the compiler: MinGW 4.9 (32-bit) and I have the QT version 5.4 or 5.5 (I am not sure). Here is a picture of his error (sadly it is in German, but I hope the google translator will help you):

Although this is not a proper distribution method, this should be enough for you now.
Copy the executable (.exe file) to another PC (or a virtual machine) without Qt installation. if you have Qt installed, it will find some libs from PATH variable (for ex, your dev PC)
Once copied, try to run that until you succeed. Until unless all the dependencies are satisfied, you will see the same error dialogue as your friend which will have dll name. Copy all the dlls required and zip the folder and send it across.
Most of the dlls are found in \Qt Dir\mingw492_32\bin and \Qt Dir\mingw492_32\plugins.
Hope this helps.

Related

Qmake on Windows

I have a project written in Qt that I have no problems compiling and running on Linux. The command line is:
qmake ../trunk/GSDTesting.pro
The process on Linux was really simple: install a few dependencies using apt and you are off.
My task is to recompile the same program on Windows using Visual Studio C++ compiler, but the problem is I don't know how to start. There is no such thing as qmake for Windows.
Can someone give me a few hints where to start. Please note that I don't know QT almost at all, my task is just to debug some issue unrelated to QT.
Are you using terminal exclusively on Windows? If so, maybe this image of example build steps straight from Qt Creater 4.14.2 may help you:
As you can see the image of the default Qt creator build steps list the file path where 'qmake.exe' can be located on a local installation of the toolchain.
If you can use a machine with a display I find using the Qt creator GUI is not all that bad.
Here is a link to the base get started page:
https://doc.qt.io/qt-5/gettingstarted.html
Here is a link to the installer download page:
https://www.qt.io/download
IMPORTANT:
You will need to make a Qt account, login to your account, and then download the open-source version of the API. The commercial version of the same source is acquired differently/seperately.
Otherwise, if you cannot use the GUI, can I request some clarification on why you cannot use Qt creator on your Windows installation?

Cannot run Qt Creator GUI outside of Qt. "The application was unable to start correctly (0xc000007b)" error

I downloaded C++ code from GitHub to tag images for training an object detector using Machine Learning.
Within Qt Creator 4.2.1 Based on Qt 5.8.0 (MSVC 2015, 32bit), I was able to compile and run the code. Unfortunately, I was not able to run the .exe outside of Qt Creator.
Initially, I received an error that
"The program can't start because libgcc_s_dw2-1.dll is missing".
Thanks to
QT The program can't start because libgcc_s_dw2-1.dll is missing, that was fixed easily by adding
"QMAKE_LFLAGS += -static"
to the .pro file. Now, when I run it I get
"The application was unable to start correctly (0xc000007b). Click OK to close the application."
I was able to reproduce the error using the simple "Hello World" default project that appears when you create a Qt Widget Application. This led me to believe something was wrong with my installation.
Based on the advice of this article: https://stackoverflow.com/questions/12099117/32-bit-qt-application-on-win-7-x64-wont-run-but-runs-fine-from-qt-creator, I used Dependency Walker to identify possible causes. I expected to see only a few items that I can follow up on. Instead, I received a list of close to 100 missing .dll files. All the files started with
"API-MS-WIN ###.DLL" or "EXT-MS ###.DLL"
where ### represent some additional text characters, for example;
"API-MS-WIN-SHCORE-STREAM-WINRT-L1-1-0.DLL"
I'm attaching a sample output.
Another suggestion was to copy over
libwinpthread-1.dll, libstdc++-6.dll, libgcc_s_dw2-1.dll.
That did not work either.
My next move was to simply get the latest version of QT and wish for the best. I installed Qt Creator 4.8.1 Based on At 5.12.0 (MSVC 2015, 32 bit). This time, I could not even get the code to run in the IDE. I received 1000+ error messages!
Based on advice from several pages, I added
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
to the .pro file and it still would not compile.
Also, I verified that the application is being built as a 32bit application. I'm running on a 64 bit Windows 10 system.
If anyone would like to take a crack at it to see if they can create a working .exe, here is the link: github.com/clavicule/BBTag
Qt provides a tool to copy the necessary dlls to the folder of your executable.
The tools is called windeployqt.exe and comes with your Qt installation. For me it is located at C:\Qt\5.9.1\msvc2015_64\bin\windeployqt.exe. You will have to look at your installation path and probably the msvc_32 folder to find it.
Then you go to the folder with your executable in it, oben a command prompt or powershell and execute path\to\windeployqt.exe yourProgram.exe and it will automatically copy the necessary dll files to this folder. Afterwards you can run your program without issues.
The official documentation for the tool can be found here.
Alternative 1: While developing you could use QtCreator which automatically adds the paths to the dlls when running your program - make sure to include them if you deploy your program!
Alternative 2: Add the path to the necessary dlls to your PATH variable. This isn't recommended either, since everyone who gets your program would have to do the same to run it.
I figured it out! My installation of Anaconda (a Python distribution popular for data science and machine learning) is the culprit.
From: #remy-lebeau
The application was unable to start correctly (0xc000007b)
The error:
"The application was unable to start correctly (0xc000007b) ..."
is a good indicator that the 32-bit app tried to load a 64-bit DLL. At first, this did not make sense since I verified many times that I was using the 32 bit version of Qt.
It turns out that the installation of the 64 bit version of Anaconda also contained many Qt5 dlls used for the PyQt5 package. Since the path to this folder came before the path to my c:\Qt...\bin folder, it was used in the build instead of the actual 32 bit version installed with Qt. This was not obvious because I was unaware of PyQt5 so I had no idea that it came with Anaconda. A simple reordering of the path entries using the System Environment Variables interface AND a system restart fixed the problem.
Silver lining: I now know C++ and designing GUIs w/ QT and PyQt5
Thanks #albertmand and #jwernerny

Can't run Qt program on another computer

I have copied my qt C++ program into another computer running the same Ubuntu version but it did not work. The terminal told that it can't find the:
libQt5PrintSupport.so.5
libQt5Core.so.5
libQt5Widgets.so.5
libQt5Gui.so.5
I then installed the qt essentials and qt base and afterwords verified that these libraries were installed but still got the same errors.
Then I tried to install the Qt creator itself but it gave me errors considering pre-build C++ files like function multiple definitions (of course no such errors on my computer)
While on my computer I even didn't have to use the LD_LIBRARY_PATH
Please help
Solve my problem:
The thing is that all Qt programs are hardware dependent and not software dependent like CODE::BLOCKS (thus will need dependencies externally)
What you have to do is install the Qt Creator and recompile your program, but wait it wont be that easy what you have to do is in the project tab disable the output folder ao that the program will be executed internally then enable the output folder and say yes so that you will rewrite your output folder

Build (compile) a basic standalone .exe application using Qt-creator on Windows 8

I have installed Qt-5.7 on windows 8 because I couldn't build my released .exe from Linux (my favorite) in order to be used on Windows OS even after searching a lot on internet (Where there have to be cross-compilation...). After the installation, I just want to make sure that I can build/run a first application (one of the examples provided by default by Qt-creator "filesystembrows") and I have follow the official guide in order to build Qt as shared libraries, but the issue is that when I type the first command line I get: 'nmake' is not recognized as an internal or external command' Also it still show the same message even though a update the variable environment of the system with C:\Qt\Qt5.7.0\5.7\mingw53_32\bin which one is the default path set-up when installing Qt on windows. Any help just to make a stand alone .exe for Windows (as shared libraries ) please
Why not build your project by using qtcreator ?
Did you test your build environnement by making a test application with qtcreator ?
P.S.: If you want, I can explain how to build application using Visual Studio as a compiler and QtCreator as an IDE.
nmake is a build tool provided with Visual Studio and with Windows SDK. You don't have it, apparently.
It seems you're using a mingw build of Qt; it comes with a bundled copy of mingw. There, the build tool is simply called make.

This application failed to start because it could not find or load the Qt platform plugin "windows"

I tried making an executable file of my program but there are some errors which I did not understand or could not find solutions of. I used my .exe file onto another computer and there was an error. I made my program through QtCreator (v 5.1.1)with my Windows 7, 64-bit laptop. There was an error when I used it in 2 32-bit laptops.
The error message says:
This application failed to start because it could not find or load the Qt platform plugin "windows".
Available platform plugins are: minimal, offscreen, windows.
Reinstalling the application may fix the problem.
I already created a new folder called "platforms" containing "qminimal.dll", "qoffscreen.dll" and "qwindows.dll" in the same level of my .exe file. I also pasted in the same level the other DLLs that my program needs.
In Qt 5.2, there is a tool that can be used for deployment on Windows: windeployqt. It will be in the bin folder of your Qt installation. It greatly simplifies deployment, so if you don't mind downloading a newer Qt version, I'd highly recommend it. It may even work with an older Qt version, but I haven't tested it.
We had exact same problem with Qt5.3.
Problem arised when we've rebuilt the Qt to reduce dependencies (e.g. Qt5Positioning, Qt5Sensors).
Created dlls were copied to different directory (source for installation), but we forgot to copy also newly created platforms plugin dlls.
The problem was fixed by using all dlls from same Qt build (with same configuration).
Your problem is probably the same: mixing dlls from different Qt builds (e.g. different configuration, version,...).