4

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?

1
  • Qt creator automatically create the executable when you compile it. Isn't it? Commented Aug 29, 2014 at 14:50

6 Answers 6

13

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.

1
  • you can add this as a Custom Process step in Qt Creator when deploying your release. Read @bogdan.bodnarescu s answer. Commented Feb 1 at 15:44
8

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.

5

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.

1

You can configure a Deploy directly in Qt Creator so that when you Run it will automatically deploy.

For this you have to go Projects and in the Deployment menu add a Custom Process step and there put as application windeployqt.exe from the /bin folder of the compiler that you are using and the path to the .exe file from the release folder.

Then you just need to right click on the project and Deploy and all the .dlls will be automatically copied together with the .exe

The disadvantage to this approach is that you need to then manually copy the release folder and rename as deployed .exe

I am trying to automate this with a batch script that calls windeploqt outside from Qt Creator and creates automatically a folder but it doesn't behave the same, it doesn't copy the same dll as when it is run from Qt Creator and I don't know why.

@echo off

REM Deploy the Qt project
C:\Qt\5.15.2\mingw81_32\bin\windeployqt.exe --quick C:\GitHub\APP\release\APP.exe --dir windeployqt

REM Get the current commit ID
for /f "tokens=1" %%i in ('git rev-parse --short HEAD') do set commit_id=%%i

REM Create the deploy folder name
set deploy_folder=deploy_%commit_id%

REM Create the deploy folder
mkdir %deploy_folder%

REM Copy the contents of the windeployqt folder to the deploy folder
xcopy /E /Y windeployqt %deploy_folder%

REM Rename the deploy folder
ren %deploy_folder% %deploy_folder:~0,-1%

REM Remove the windeployqt folder
rmdir /S /Q windeployqt
2
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – CPlus
    Commented Nov 20, 2023 at 19:14
  • This is the best way in my opinion. This way I dont have to execute windeploy.exe myself. But the resulting release-folder is still 60MB even though the app doesnt do much. Commented Feb 1 at 15:41
0

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

0

Steps to make an exe file from your qt project

  1. In Build Settings make sure Edit build configuration is Release.

  2. 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).

  3. Build and run you project(This will create a release directory inside of yours project folder).

  4. 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).

  5. Copy all folders from C:\Qt\6.3.2\mingw_64\plugins to the release folder.

  6. Now you can launch the exe file inside of your release folder corresponding to your project.

qt settings

1
  • After doing that my release directory was 200MB. (the app doesnt do much) It does work though. Commented Feb 1 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.