Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Customizing Application Icons and Packaging Qt Projects for Windows

Tech May 9 4

Configuring Icons in Qt 6.7.2 on Windows

Using CMake

Setting the Executable Icon

  1. Prepare an icon file named app_icon.ico.

  2. Create a resource script file named icon_resource.rc with the following content:

    IDI_ICON1 ICON "app_icon.ico"
    
  3. Add app_icon.ico and icon_resource.rc to your Qt Resource File (e.g., assets.qrc). You can do this by right-clicking the .qrc file in the project tree and selecting "Add Existing Files...".

  4. Update your CMakeLists.txt to 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()
    
  5. Rebuild the project. The generated MyAppProject.exe will now display the custom icon.

Setting the Window Title Bar Icon

  1. Ensure app_icon.ico is included in your resource file (assets.qrc).
  2. In the Qt Designer for your main window, locate the "windowIcon" property in the Property Editor.
  3. Click the dropdown arrow, select "Choose Resource", and navigate to your app_icon.ico.
  4. Run the appplication to see the icon applied to the top-left corner of the window.

Using qmake

Setting the Executable Icon

  1. Add the icon to your resource file as described above.

  2. Open your project file (e.g., MyProject.pro) and append the following line, adjusting the path to where your .ico file resides within the project:

    RC_ICONS = assets/app_icon.ico
    
  3. 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

  1. Compile your project in Release mode using MinGW to generate the executable.

  2. Move the resulting .exe file into a new, empty directory.

  3. Launch the "Qt 6.7.2 (MinGW 11.2.0 64-bit)" command prompt from the Start menu.

  4. Navigate to the directory containing your executable.

  5. Run the deployment tool:

    windeployqt MyAppProject.exe
    
  6. The tool copies all necessary DLLs and plugins into the folder. You can now run MyAppProject.exe independently.

Using MSVC Compiler

  1. Compile your project in Release mode using MSVC (e.g., 2022) and place the .exe in a new folder.

  2. Open the "Qt 6.7.2 (MSVC 2019 64-bit)" command prompt.

  3. Navigate to your executable's directory and execute the same deployment command:

    windeployqt MyAppProject.exe
    
  4. The application is now packaged with its dependencies.

Tags: qtC++cmake

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.