How to make .exe file in Qt Creator - c++

I was working on Qt Creator compiler to make a simple text editor. I did that but now want to make an .exe file of that project, but I don't know how to make an .exe file in Qt Creator compiler. Can anyone help?

There is a tool that adds the .dlls automatically on windows.
In the command prompt navigate to your qt bin directory. It should look something like this: ...\Qt\5.9.1\msvc2017_64\bin\ (I'm using visual studio).
Run windeployqt.exe in the command prompt with your project location as the argument like this:
windeployqt.exe C:\project_folder\my_project.exe
Now my_project.exe will have the .dlls in the same directory and will execute.

The executable is generated by the compiler when you build your application. To know where the executable is stored, look into
Projects (CTRL+5) -> Build settings -> General -> Build directory
This is where Qt creator will put the .exe it generates if you have shadow build enabled.
If shadow build is disabled, the executable will be stored inside the project folder itself.

From:
How to create executable file for a Qt Application?
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.

I had the same problem so I used the suggested above answer:
"
There is a tool that adds the .dlls automatically on windows.
In the command prompt navigate to your qt bin directory. It should look something like this: ...\Qt\5.9.1\msvc2017_64\bin\ (I'm using visual studio).
Run windeployqt.exe in the command prompt with your project location as the argument like this:
windeployqt.exe C:\project_folder\my_project.exe
Now my_project.exe will have the .dlls in the same directory and will execute.
"
but there somethings that I did so this might help:
there is already an executable version of your app in the debug file of your project if you can't find it try to enter properties in Qt creator an track down the file. while you are at it in properties you can also see whether your app is using msvc2017_64 like in the previous answer or other compilers.
Take that file to the same path you write in the command line here: windeployqt.exe C:\project_folder\my_project.exe.
when your try to open the executable file it will till it needs some dlls files that you can find in this path .\Qt\5.9.1\msvc2017_64\bin copy and paste them in the location of the exe file

Steps to make an exe file from your qt project
In Build Settings make sure Edit build configuration is Release.
In Build Settings uncheck Shadow build(this will make sure that the release folder is inside of your project directory instead of outside of your project directory).
Build and run you project(This will create a release directory inside of yours project folder).
Copy *.dll and *.exe file from C:\Qt\6.3.2\mingw_64\bin to the release folder (where your projects exe file is there).
Copy all folders from C:\Qt\6.3.2\mingw_64\plugins to the release folder.
Now you can launch the exe file inside of your release folder corresponding to your project.

Related

DLL's dependency cannot be found when DLL moved to another location

I'm on Windows 10, Visual Studio 2017, x64 build . . .
I have a DLL that I'm using in an exe project. We'll call it, myLibrary.dll. It comes with a .lib companion file as well. The myLibrary.dll has some other DLL dependencies that it is using. We'll call that one theDependency.dll.
I've linked the companion myLibrary.lib file in my project through Linker --> General --> Additional Library Dependencies properties. Added myLibrary.lib to the Additional Dependencies.
When I build my project, I use post build event to copy the myLibrary.dll to the Release/Debug directory of my project.
This works fine.
My issue is when I try to use myLibrary.dll in a different exe project. I get an error that it cannot find the theDependency.dll. I've used all the same property setup as the first exe project. As a test, I moved the build directory of the first exe project to another location (on the same computer) and I get the same error. "Cannot find theDependency.dll"
How is myLibrary.dll targeting it's dependencies? Not sure why the 2nd project gets this error? Also, not sure why moving the files gets this error?
Any ideas? Thanks.
Adding the path of the dll to the PATH environment variable worked for me.

Building a Qt executable in Visual Studio 2017

I made a Qt Application in Visual Studio and it works when I run it in the program. However then I build the solution and try to run the executable errors pop up that certain .dll files are not found(QtWidgets.dll, QtCore.dll,QtCored.dll etc.). How can I fix this?
To make your application ready for deployment, you can use windeployqt.
It is a commandline program that comes with Qt and collects all the required dependencies of your executable. Go to your QTDIR/bin/ folder and run this command
windeployqt <path-to-app-binary.exe>
It will scan your binary and copy everything that is needed next to it. For further details, have a look at the documentation.
Well, you have two options:
If you want to distribute your application, you have to copy the required DLLs to the folder where your executable is. You can do this either by copying them manually or you write a script for this. The DLLs are in the binary folder of your Qt installation, e.g.
Qt\5.12.2\mingw73_64\bin
Add the above mentioned folder to your system PATH variable, then the DLLs should be found by your application.

Qt application release exe not running

I have built a very simple calculator in Qt. When I run it in release mode from qt creator, everything works fine. However when I go to the release folder and run it, it gives QT5Core.dll, QT5Widgets.dll and QT5Gui.dll not found. After running windeployqt there by:
windeployqt .
All the dll get added. However, it then gives error VCRUNTIME140_APP.dll and MSVCP140_APP.dll not found. After copying them to the folder. The exe doesn't give any error on double clicking but just does not start. What should I do?
I found this solution here, however I cannot find any qml file in the application directory.
I created it as a QT widget application. I am using Windows 10 with Visual Studio 2017 and MSVC2017 64bit desktop kit. The application is in C++.
Update:
Running the command
windeployqt Calculator.exe
after adding qt to the path seems to do the trick. Application working even after removing qt from the path. Will try running the app inside vm just to be extra sure.
When running from the command line, add your Qt Bin directory to the PATH. For example:
C:\> PATH=C:\Qt\Qt5.11.0\5.11.0\msvc2017_64\bin;%PATH%
You can solve the problem as selbie described it. An another way is to copy the missing .dll-Files to the folder where the.exe is placed.
See here https://doc.qt.io/Qt-5/windows-deployment.html#creating-the-application-package :
To deploy the application, we must make sure that we copy the relevant Qt DLLs (corresponding to the Qt modules used in the application) and the Windows platform plugin, qwindows.dll, as well as the executable to the same directory tree in the release subdirectory.
set variable VCINSTALLDIR, example:
set VCINSTALLDIR=p:\Programs\Microsoft Visual Studio\2017\Community\VC\
and next run
windeployqt.exe app.exe
Or copy vc_redist.x64.exe from Redist subfolder into folder with your application.
As #mosa mentioned, To deploy the application, we must make sure that we copy the relevant Qt DLLs (corresponding to the Qt modules used in the application) and the Windows platform plugin, qwindows.dll, as well as the executable to the same directory tree in the release subdirectory.
To add missing .dll files first open QT MSVC Console and type windeployqt.exe command,
Then you have to go to the directory which .exe file contains. Let's assume my .exe is in the desktop,
C:/
cd user/indrajith/desktop
Then you can add missing .dll files using following command,
windeployqt.exe --quick.
Finally, just double click your .exe file to run the program.
Simple Solution:
Copy "bin" and "plugins" folders from the qt setup directory(C:\Qt\6.2.4\mingw_64) to your release folder.
Put your .exe file inside that "bin" folder and done.
Now, your .exe application should run.The bin and plugin folders contain required .dll files and unnecessary files can be removed manually.

visual studio 2013 deploy a project

I crack my head already, I need to deploy a project. I tried to use InstallShield, it create an msi file, and local installation has no errors, but then when I tried to launch the program it output "debug error". In my settings code generator -> runtime library set for Multi-threaded Debug DLL(/MDd). If I'll set it to Multi-threaded (/MT) it would not compile: "Please use the /MD switch for _AFXDLL builds"
Then I tried to use VS Installer project extension. It creates the msi and setup file, but after I install it, I can't find the .exe file and launch program. What I am doing wrong?
Folder with project files
![enter image description here][3]
Folder with exe file
![enter image description here][4]
At the stage of creating the installer for your program, you have to put all the external files, libraries and resources, that your program needs in order to run correctly, in your program's working directory. When you run the program via Visual Studio, everything works fine since it can find the files, because, as you've mentioned, they are in the project folder, and the project folder is where Visual Studio is looking for them.
When you launch your program outside VS, the program can't find these files since it by default tries to locate them in the folder in which the .exe file being run is located. So, if you wan't to run program outside VS, you need to put all the files needed to your .exe's directory.
For the same reason, while creating your installer, you need to include all the files necessary in the installation target directory together with your .exe. Every installer creator lets you do that.
In general, if you cannot run your program outside any IDE, and you can run it within that IDE, it is a rule of thumb that you should first check if you have included all the necessary files/libraries/dll's/etc. in your program's working directory.
I solved it!!!!!!!!
1)Help to run .exe file, helped updating .uld file in the same directory as a exe file.
2)I used Dependency Walker (http://www.dependencywalker.com/) to find all dll that it's need. And then I create a Setup Project using Wizard at the "Choose file to include" step I add every file and every library that it's depend on! Build->Install-> Then magic, and my application installed and running! Thank you all for your help

Project cannot load image assets while running from visual studio IDE

I am porting an old visual studio C++ project. I have a data folder in the project directory that contains all the image assets. The project is build using an external make file.
My problem is, the project cannot load the asset files while running the executable from the VS IDE during debugging. However, if I execute the exe from bin folder, it can load the assets.I am assuming there are some kind of environment issue in the project, but could not figured it out.
Any clue?
My guess is that the program tries to access the assets using a relative path like ..\data\some.data. It works when you run it manually from the bin folder, because the current directory is set to the bin folder itself (the folder from where an application was launched) by default.
But when running projects from the Visual Studio IDE, parameters set under "Project properties > Debugging" tab apply instead. There is an option "Working directory", which defaults to $(ProjectDir), i.e. the folder where the project file resides.
Try changing that to the bin folder, or, if the resulting .exe file is placed directly there, easily just to the $(OutDir) variable.