Как сделать .exe файл в Qt Creator
Я работал над компилятором Qt Creator, чтобы создать простой текстовый редактор. Я сделал это, но теперь хочу сделать .exe файл этого проекта, но я не знаю, как сделать файл .exe в компиляторе Qt Creator. Может ли кто-нибудь помочь?
3 ответа
From: Как создать исполняемый файл для приложения Qt? В основном вам нужно искать подпапку MinGW глубоко в Qt-дерево, где утилиты Qt находятся и копируют необходимые DLL файлы.
Ниже приведены шаги, которые я следую на основе Qt 4.7.4, для упаковки приложения с использованием правильных разделяемых библиотек.
Скажем, вы установили Qt под c:\qtsdk. Откройте свой проект и скомпилируйте его в режиме выпуска. Перейдите в этот каталог: C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin — он содержит все разделяемые библиотеки. Отладочные библиотеки заканчиваются на «d» — frex, QtCore.dll — это версия выпуска, а QtCoreD.dll — отладочная версия. Скопируйте хотя бы эти файлы в каталог выпуска (где находится ваш.exe):
- MINGWM10.DLL
- libgcc_s_dw2-1.dll
- QtCore4.dll
- qtgui4.dll
Я только что построил, протестировал и развернул фиктивный проект таким образом.
Исполняемый файл генерируется компилятором при создании приложения. Чтобы узнать, где хранится исполняемый файл, загляните в
Projects (CTRL+5) → Build settings → General → Build directory
Это то, где создатель Qt поставит.exe, который он генерирует, если у вас включена функция shadow build. Если теневая сборка отключена, исполняемый файл будет храниться внутри самой папки проекта.
Creating small executables with Qt Creator and MingW
Starting with an empty Plain C Project in Qt Creator IDE and gcc from MinGW as compiler, I will show you how to generate small binaries that are independent from MinGW dlls. At the writing of this article the app versions that I used were Qt Creator 2.6.2 with Qt 5.0.1 and gcc 4.7.2.
Replace the code of the main.c with following:
Switch the build configuration in menu Projects from Debug to Release and compile the project (Ctrl + B is the default shortcut for this). This will result in a 9.728 byte big exe file. The file content, split in parts, looks like this:

This is the portable executable header, containing 8 section definitions (.text, .data, .rdata, .eh_fram, .bss, .idata, .CRT, .tls).

The code section is nearly as twice as huge as the one generated by Visual Studio compiler and of cause way more than we want inside our exe for calling 2 API functions.

In the import section you can see that it not only includes the Microsoft Visual C Run-Time Library, but also the MingW runtime.
Let’s pimp the project to remove all the stuff that we did not want included in the exe file:
- Open the .pro file of your project and replace it with following:
- If you try to build the project now you will get an linker error about undefined reference to `__main’. To fix this issue we just rename the main function in our c file:
Recompile the project and your compiled exe will have a size of 2.048 byte and look so fresh and so clean like this:
How to make .exe file in Qt Creator
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?
![]()
![]()
5 Answers 5
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:
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:
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
C++ – How to make .exe file in Qt Creator
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?
Best Solution
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:
Now my_project.exe will have the .dlls in the same directory and will execute.
Related Solutions
C++ – How to set, clear, and toggle a single bit
Setting a bit
Use the bitwise OR operator ( | ) to set a bit.
That will set the n th bit of number . n should be zero, if you want to set the 1 st bit and so on upto n-1 , if you want to set the n th bit.
Use 1ULL if number is wider than unsigned long ; promotion of 1UL << n doesn't happen until after evaluating 1UL << n where it's undefined behaviour to shift by more than the width of a long . The same applies to all the rest of the examples.
Clearing a bit
Use the bitwise AND operator ( & ) to clear a bit.
That will clear the n th bit of number . You must invert the bit string with the bitwise NOT operator (
Toggling a bit
The XOR operator ( ^ ) can be used to toggle a bit.
That will toggle the n th bit of number .
Checking a bit
You didn't ask for this, but I might as well add it.
To check a bit, shift the number n to the right, then bitwise AND it:
That will put the value of the n th bit of number into the variable bit .
Changing the nth bit to x
Setting the n th bit to either 1 or 0 can be achieved with the following on a 2's complement C++ implementation:
Bit n will be set if x is 1 , and cleared if x is 0 . If x has some other value, you get garbage. x = !!x will booleanize it to 0 or 1.
To make this independent of 2's complement negation behaviour (where -1 has all bits set, unlike on a 1's complement or sign/magnitude C++ implementation), use unsigned negation.
It's generally a good idea to use unsigned types for portable bit manipulation.
(1UL << n)) will clear the n th bit and (x << n) will set the n th bit to x .
It's also generally a good idea to not to copy/paste code in general and so many people use preprocessor macros (like the community wiki answer further down) or some sort of encapsulation.
C++ – How to automatically generate a stacktrace when the program crashes
For Linux and I believe Mac OS X, if you're using gcc, or any compiler that uses glibc, you can use the backtrace() functions in execinfo.h to print a stacktrace and exit gracefully when you get a segmentation fault. Documentation can be found in the libc manual.
Here's an example program that installs a SIGSEGV handler and prints a stacktrace to stderr when it segfaults. The baz() function here causes the segfault that triggers the handler:
Compiling with -g -rdynamic gets you symbol info in your output, which glibc can use to make a nice stacktrace:
Executing this gets you this output:
This shows the load module, offset, and function that each frame in the stack came from. Here you can see the signal handler on top of the stack, and the libc functions before main in addition to main , foo , bar , and baz .