[office/crow-translate] /: Fix missing application icon on Windows and macOS

Mauritius Clemens <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 39a0e0f186c5aa1a6106fe4e2848ceb795388fa3 by Mauritius Clemens.
Committed on 16/08/2026 at 21:39.
Pushed by pillowtrucker into branch 'master'.

Fix missing application icon on Windows and macOS

The build splits crow-translate into a static library plus a thin
executable (for the test suite). Two resources attached to the library
get lost in that split, each for the same reason: MSVC drops resources
compiled into a static library when the final executable does not
reference them.

- app.qrc (the embedded hicolor theme with the application icon) was
  never registered: register it explicitly with Q_INIT_RESOURCE(app) on
  Windows and macOS, where it is the only icon source (no installed
  system themes)
- WINDOWS_ICON.rc (the .ico embedded via ecm_add_app_icon) was compiled
  into the library: also attach it to the executable target so IDI_ICON1
  is linked into crow.exe and Explorer/taskbar show the real icon

M  +10   -0    CMakeLists.txt
M  +8    -0    src/main.cpp

https://invent.kde.org/office/crow-translate/-/commit/39a0e0f186c5aa1a6106fe4e2848ceb795388fa3

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0e5f0b6..7b11aa6f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -292,6 +292,16 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME})
 # Link executable against library
 target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}-lib)
 
+# ecm_add_app_icon() attaches WINDOWS_ICON.rc to the static library above.
+# The MSVC linker drops resources that are compiled into a static library
+# when the executable does not reference them (resources expose no symbol
+# that would force the object to be pulled in), so the application icon
+# never ends up in crow.exe and Windows shows a generic icon. Attach the
+# .rc to the executable as well so IDI_ICON1 is always embedded.
+if(WIN32 AND WINDOWS_ICON)
+    target_sources(${PROJECT_NAME} PRIVATE ${WINDOWS_ICON})
+endif()
+
 # Note: ONNX Runtime configuration moved after find_package(ONNXRuntime) below
 
 # Handle espeak-ng submodule for Piper TTS
diff --git a/src/main.cpp b/src/main.cpp
index ac0719b8..ab9c57a3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -48,6 +48,14 @@ int launchGui(int argc, char *argv[])
 {
     Q_INIT_RESOURCE(engines);
     Q_INIT_RESOURCE(icon_theme);
+#if defined(Q_OS_WIN) || defined(Q_OS_DARWIN)
+    // app.qrc (which holds the application icon) is only compiled into the
+    // STATIC crow-translate-lib on Windows and macOS (see the APPLE/WIN32
+    // target_sources blocks in CMakeLists.txt). Nothing references the
+    // resource initializer from the executable, so the linker drops it and
+    // QIcon::fromTheme() cannot find :/icons/hicolor. Register it here.
+    Q_INIT_RESOURCE(app);
+#endif
 
 #ifdef WITH_KICONTHEMES
     // Set up KDE icon theming before the application object exists (required;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.