Customizing Application Icons and Packaging Qt Projects for Windows
Configuring Icons in Qt 6.7.2 on Windows
Using CMake
Setting the Executable Icon
-
Prepare an icon file named
app_icon.ico. -
Create a resource script file named
icon_resource.rcwith the following content:IDI_ICON1 ICON "app_icon.ico" -
Add
app_icon.icoandicon_resource.rcto your Qt Resource File (e.g.,assets.qrc). You can do this by right-clicking the.qrcfile in the project tree and selecting "Add Existing Files...". -
Update your
CMakeLists.txtto enclude the resource script in the executable definition. Ensure the path matches your project structure:if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(MyAppProject MANUAL_FINALIZATION ${PROJECT_SOURCES} assets.qrc ${CMAKE_CURRENT_SOURCE_DIR}/assets/icon_resource.rc ) endif() -
Rebuild the project. The generated
MyAppProject.exewill now display the custom icon.
Setting the Window Title Bar Icon
- Ensure
app_icon.icois included in your resource file (assets.qrc). - In the Qt Designer for your main window, locate the "windowIcon" property in the Property Editor.
- Click the dropdown arrow, select "Choose Resource", and navigate to your
app_icon.ico. - Run the appplication to see the icon applied to the top-left corner of the window.
Using qmake
Setting the Executable Icon
-
Add the icon to your resource file as described above.
-
Open your project file (e.g.,
MyProject.pro) and append the following line, adjusting the path to where your.icofile resides within the project:RC_ICONS = assets/app_icon.ico -
Perform a full rebuild (Clean and Rebuild) of the project. The executable icon will update.
Setting the Window Title Bar Icon
The process is identical to the CMake method: set the windowIcon property in Qt Designer using the resource file.
Deploying Qt Applications on Windows
Using MinGW Compiler
-
Compile your project in Release mode using MinGW to generate the executable.
-
Move the resulting
.exefile into a new, empty directory. -
Launch the "Qt 6.7.2 (MinGW 11.2.0 64-bit)" command prompt from the Start menu.
-
Navigate to the directory containing your executable.
-
Run the deployment tool:
windeployqt MyAppProject.exe -
The tool copies all necessary DLLs and plugins into the folder. You can now run
MyAppProject.exeindependently.
Using MSVC Compiler
-
Compile your project in Release mode using MSVC (e.g., 2022) and place the
.exein a new folder. -
Open the "Qt 6.7.2 (MSVC 2019 64-bit)" command prompt.
-
Navigate to your executable's directory and execute the same deployment command:
windeployqt MyAppProject.exe -
The application is now packaged with its dependencies.