How to set the application icon on Windows using cmake ?
-
Hello,
I am trying to set the application icon using .rc file and ico for icon.
But i need the correct cmake command to set the icon file to exe..rc file contains as below:
IDI_ICON1 ICON DISCARDABLE "appicon.ico"Following is what i have in my cmake file:
SET(WINDOWS_RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc)
QT5_ADD_RESOURCES(RESOURCE ${WINDOWS_RESOURCE_PATH})
QT5_WRAP_CPP(SAMPLEAPP_HDRS_MOC ${SAMPLEAPP_HDRS_QT_MOC})
ADD_EXECUTABLE(SampleApp ${SAMPLEAPP_SRCS} ${SAMPLEAPP_HDRS_MOC} ${WINDOWS_RESOURCE_PATH})But i am getting following error:
Error 1 error : 'C:/SampleApp/appicon.rc' Line: 1 Column: 1 [Start tag expected.] C:\SampleApp\buildQt541_win64-trunk\CUSTOMBUILDPlease let me know what am I doing wrong here.
or Please share a sample code to do the same.Thank you.
-
Hi,
Did you check that your file contains the correct white spaces ?
-
@QtVik That's not how you add windows resources.
qt5_add_resources()
is for qrc files or Qt Resources.To add your rc to your exe, you just do:
add_executable(${PROJECT_NAME} ${SRCS} project.rc)
project.rc would be whatever you name your resource file.
-
@ambershark good catch ! I missed that one.
-
Hi @QtVik
@SGaist , @ambershark thanks for the answer for using cmake.
@QtVik can u mark as solved, so the others users can get the solution for the above mentioned post.Thanks,
-
Hello @ambershark @SGaist ,
It worked fine on windows.
But I am unable to see the icon on Linux.
Is there any different trick to make it work on Linux ?Hello @Pradeep-Kumar ,
Shall I mark this as solved after I receive answer on Linux issue? -
@QtVik Well that's kind of a different question. Linux doesn't use rc files like windows does.
There are a few different things for setting icons in linux. There is the application icon that you set with a call to
QApplication::setIcon
orQWindow::setIcon
.Then there is the window manager icon. That depends on which desktop you want to support. Here is help on that http://doc.qt.io/qt-5/appicon.html.
But what I mostly do is just set it in the desktop entry file I use for my app.
I.e.
[Desktop Entry] Name=My App Type=Application Exec=/path/to/my/app Icon=/path/to/my/icon/file.png Comment=My cool app
That's like the linux equivalent of a shortcut in windows. It will set your icon for you.
-
Thank you so much @ambershark .
I was more concerned about the window manger Icon.
Will try it out.