Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Icon for linux application
Qt 6.11 is out! See what's new in the release blog

Icon for linux application

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 8 Posters 5.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #13

    This should work the way you did it. Do you see that rc.exe is executed during compilation? It should create a .res file which then gets linked into the resulting executable

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    0
    • Joe von HabsburgJ Offline
      Joe von HabsburgJ Offline
      Joe von Habsburg
      wrote on last edited by
      #14

      @Christian-Ehrlicher said in Icon for linux application:

      This should work the way you did it.

      I did something wrong probably.

      @Christian-Ehrlicher said in Icon for linux application:

      Do you see that rc.exe is executed during compilation?

      I see only that icon : image.png

      I didn't quite understand what you meant. Are you referring to my application as rx.exe? If so, and by compilation you mean build and run, I don't see it.

      @Christian-Ehrlicher said in Icon for linux application:

      It should create a .res file which then gets linked into the resulting executable

      When I look in the build folder, I don't see any files with a .res extension. Do I need to build it differently?

      Christian EhrlicherC 1 Reply Last reply
      0
      • Joe von HabsburgJ Joe von Habsburg

        @Christian-Ehrlicher said in Icon for linux application:

        This should work the way you did it.

        I did something wrong probably.

        @Christian-Ehrlicher said in Icon for linux application:

        Do you see that rc.exe is executed during compilation?

        I see only that icon : image.png

        I didn't quite understand what you meant. Are you referring to my application as rx.exe? If so, and by compilation you mean build and run, I don't see it.

        @Christian-Ehrlicher said in Icon for linux application:

        It should create a .res file which then gets linked into the resulting executable

        When I look in the build folder, I don't see any files with a .res extension. Do I need to build it differently?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #15

        @Joe-von-Habsburg said in Icon for linux application:

        I didn't quite understand what you meant

        When you compile the application in QtCreator you see what/how the compiler is invoked. There you see a lot of output and one of them should be the invocation of rc.exe. You need to clean the build dir before or at least modify the rc file so it gets recompiled.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • Joe von HabsburgJ Offline
          Joe von HabsburgJ Offline
          Joe von Habsburg
          wrote on last edited by
          #16

          I looked at the "Compile Output" window and, it is finished succesfully. I could not see about icon or rc.exe.

          [15/15 10.2/sec] Linking CXX executable MyApp
          16:28:18: The command "/home/x/Qt/Tools/CMake/bin/cmake --build /home/x/Desktop/MyApp/build --target all" finished successfully.
          

          I want to ask again, is rc.exe my app or different thing ? If different thing how can I add to my app, and why should I add ?
          I clear cmake configuration, I run cmake, I clean and rebuild. Still icon does not exist.

          I've worked this hard on Qt in Ubuntu before. I apologize if I did anything wrong.

          Christian EhrlicherC 1 Reply Last reply
          0
          • Joe von HabsburgJ Joe von Habsburg

            I looked at the "Compile Output" window and, it is finished succesfully. I could not see about icon or rc.exe.

            [15/15 10.2/sec] Linking CXX executable MyApp
            16:28:18: The command "/home/x/Qt/Tools/CMake/bin/cmake --build /home/x/Desktop/MyApp/build --target all" finished successfully.
            

            I want to ask again, is rc.exe my app or different thing ? If different thing how can I add to my app, and why should I add ?
            I clear cmake configuration, I run cmake, I clean and rebuild. Still icon does not exist.

            I've worked this hard on Qt in Ubuntu before. I apologize if I did anything wrong.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #17

            @Joe-von-Habsburg said in Icon for linux application:

            I've worked this hard on Qt in Ubuntu before

            You're aware that the rc application icon is for windows??? Please read the full thread.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • Joe von HabsburgJ Offline
              Joe von HabsburgJ Offline
              Joe von Habsburg
              wrote on last edited by
              #18

              Ok, I am sorry, I read : https://forum.qt.io/topic/102167/how-to-add-qt-application-icon-in-ubuntu
              I need both of them also, .destop file and QMainWindow::setWindowIcon().

              I create icon.destop file and add resouces.qrc and add also to build folder.
              My file :

              [Desktop Entry]
              Version=1.0
              Type=Application
              Name=MyApp
              Icon=Resources/icon/icon.png
              Exec=MyApp
              Comment=MyApp Application
              Categories=Application
              Terminal=false
              

              I could not see any thing.
              And QMainWindow::setWindowIcon(). not work.
              a6acd848-c7f7-4f4b-a406-417ba4fe9b6a-image.png

              I checked, is icon null, it is return false. icon is not null.

              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
                  QIcon ic(":/Resources/icon/icon.png");
                  qDebug() << "ic.isNull" << ic.isNull(); // return false
                  QMainWindow::setWindowIcon(QIcon(":/Resources/icon/icon.png"));
              }
              

              Did I create .destop file correct location ?

              JonBJ 1 Reply Last reply
              0
              • Joe von HabsburgJ Joe von Habsburg

                Ok, I am sorry, I read : https://forum.qt.io/topic/102167/how-to-add-qt-application-icon-in-ubuntu
                I need both of them also, .destop file and QMainWindow::setWindowIcon().

                I create icon.destop file and add resouces.qrc and add also to build folder.
                My file :

                [Desktop Entry]
                Version=1.0
                Type=Application
                Name=MyApp
                Icon=Resources/icon/icon.png
                Exec=MyApp
                Comment=MyApp Application
                Categories=Application
                Terminal=false
                

                I could not see any thing.
                And QMainWindow::setWindowIcon(). not work.
                a6acd848-c7f7-4f4b-a406-417ba4fe9b6a-image.png

                I checked, is icon null, it is return false. icon is not null.

                MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                    QIcon ic(":/Resources/icon/icon.png");
                    qDebug() << "ic.isNull" << ic.isNull(); // return false
                    QMainWindow::setWindowIcon(QIcon(":/Resources/icon/icon.png"));
                }
                

                Did I create .destop file correct location ?

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #19

                @Joe-von-Habsburg said in Icon for linux application:

                Icon=Resources/icon/icon.png

                QIcon ic(":/Resources/icon/icon.png");

                The first looks in the filing system for Resources/icon/icon.png, which doesn't exist. I do not think you can tell desktop to use a resource in a Qt executable, or I don't know how if you can (unless :/Resources/icon/icon.png works which I doubt). For the desktop shortcut I imagine you have to extract or copy the png file so you can point to that.

                Joe von HabsburgJ 1 Reply Last reply
                0
                • JonBJ JonB

                  @Joe-von-Habsburg said in Icon for linux application:

                  Icon=Resources/icon/icon.png

                  QIcon ic(":/Resources/icon/icon.png");

                  The first looks in the filing system for Resources/icon/icon.png, which doesn't exist. I do not think you can tell desktop to use a resource in a Qt executable, or I don't know how if you can (unless :/Resources/icon/icon.png works which I doubt). For the desktop shortcut I imagine you have to extract or copy the png file so you can point to that.

                  Joe von HabsburgJ Offline
                  Joe von HabsburgJ Offline
                  Joe von Habsburg
                  wrote on last edited by
                  #20

                  @JonB said in Icon for linux application:

                  Icon=Resources/icon/icon.png

                  thay are in same directory.

                  • icon.destop

                  • Resources/

                  I added on project location and build location. So it exists.

                  @JonB said in Icon for linux application:

                  I do not think you can tell desktop to use a resource in a Qt executable,

                  I know what you mean. You think I'm using a file in resources.qrc, but I copied Resources/icon/icon.png to the build folder myself. So I know you can't use it from the .qrc file, it's inside the icon.desktop file.

                  @JonB said in Icon for linux application:

                  QIcon ic(":/Resources/icon/icon.png");

                  That was for mainwindow icon. I tested for access to icon.png file or it is null, app can access to file because it returns as false for ask is it null.

                  JonBJ 1 Reply Last reply
                  0
                  • Joe von HabsburgJ Joe von Habsburg

                    @JonB said in Icon for linux application:

                    Icon=Resources/icon/icon.png

                    thay are in same directory.

                    • icon.destop

                    • Resources/

                    I added on project location and build location. So it exists.

                    @JonB said in Icon for linux application:

                    I do not think you can tell desktop to use a resource in a Qt executable,

                    I know what you mean. You think I'm using a file in resources.qrc, but I copied Resources/icon/icon.png to the build folder myself. So I know you can't use it from the .qrc file, it's inside the icon.desktop file.

                    @JonB said in Icon for linux application:

                    QIcon ic(":/Resources/icon/icon.png");

                    That was for mainwindow icon. I tested for access to icon.png file or it is null, app can access to file because it returns as false for ask is it null.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #21

                    @Joe-von-Habsburg
                    I do not understand your English or what you are saying.

                    .qrc is not relevant, it is only used at compilation time. Ubuntu/desktop will not look for Icon=Resources/icon/icon.png as an embedded resource within your executable, nor if you specify it as any Icon=:/... like you can inside Qt code.

                    Let's say your home directory is /home/joe. Copy icon.png to that directory, so /home/joe/icon.png. Specify Icon=/home/joe/icon.png in .desktop file. Try that. If that does not work then perhaps you have something wrong in your .desktop file.

                    Joe von HabsburgJ 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Joe-von-Habsburg
                      I do not understand your English or what you are saying.

                      .qrc is not relevant, it is only used at compilation time. Ubuntu/desktop will not look for Icon=Resources/icon/icon.png as an embedded resource within your executable, nor if you specify it as any Icon=:/... like you can inside Qt code.

                      Let's say your home directory is /home/joe. Copy icon.png to that directory, so /home/joe/icon.png. Specify Icon=/home/joe/icon.png in .desktop file. Try that. If that does not work then perhaps you have something wrong in your .desktop file.

                      Joe von HabsburgJ Offline
                      Joe von HabsburgJ Offline
                      Joe von Habsburg
                      wrote on last edited by
                      #22

                      @JonB said in Icon for linux application:

                      I do not understand your English or what you are saying.

                      Sorry for that.

                      @JonB said in Icon for linux application:

                      Let's say your home directory is /home/joe. Copy icon.png to that directory, so /home/joe/icon.png. Specify Icon=/home/joe/icon.png in .desktop file. Try that. If that does not work then perhaps you have something wrong in your .desktop file.

                      I said that. I copied the image same directory(build) with .desktop file.

                      000c42ac-595e-4949-a3cd-65b5019af013-image.png

                      JonBJ 1 Reply Last reply
                      0
                      • Joe von HabsburgJ Joe von Habsburg

                        @JonB said in Icon for linux application:

                        I do not understand your English or what you are saying.

                        Sorry for that.

                        @JonB said in Icon for linux application:

                        Let's say your home directory is /home/joe. Copy icon.png to that directory, so /home/joe/icon.png. Specify Icon=/home/joe/icon.png in .desktop file. Try that. If that does not work then perhaps you have something wrong in your .desktop file.

                        I said that. I copied the image same directory(build) with .desktop file.

                        000c42ac-595e-4949-a3cd-65b5019af013-image.png

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #23

                        @Joe-von-Habsburg said in Icon for linux application:

                        I said that. I copied the image same directory(build) with .desktop file.

                        It's quite simple. I suggested you:

                        1. Copy icon.png to /home/joe/icon.png (whatever your home directory is).
                        2. Put Icon=/home/joe/icon.png (that's whatever full path) in .desktop file.

                        I don't know what your screenshot is supposed to be showing me. I never said to put anything anywhere near a Resources directory or in your "build" area. And your .desktop file is in somewhere like ~/.local/share/applications/, right?

                        1 Reply Last reply
                        0
                        • Joe von HabsburgJ Offline
                          Joe von HabsburgJ Offline
                          Joe von Habsburg
                          wrote on last edited by Joe von Habsburg
                          #24

                          I add to home

                          Screenshot from 2026-04-20 11-02-06.png

                          Build directory

                          Screenshot from 2026-04-20 11-07-27.png

                          [Desktop Entry]
                          Version=1.0
                          Type=Application
                          Name=App
                          Icon=/home/x/icon.png
                          Exec=myapp
                          Comment=My Application
                          Categories=Application
                          Terminal=false
                          

                          Icon is :
                          icon.png

                          I saw that
                          fab9ae44-410d-4834-a9be-1e2dd7f7ee05-image.png

                          @JonB said in Icon for linux application:

                          desktop file is in somewhere like ~/.local/share/applications/, right?

                          should i create .destop file in there ?

                          JonBJ 1 Reply Last reply
                          0
                          • Joe von HabsburgJ Joe von Habsburg

                            I add to home

                            Screenshot from 2026-04-20 11-02-06.png

                            Build directory

                            Screenshot from 2026-04-20 11-07-27.png

                            [Desktop Entry]
                            Version=1.0
                            Type=Application
                            Name=App
                            Icon=/home/x/icon.png
                            Exec=myapp
                            Comment=My Application
                            Categories=Application
                            Terminal=false
                            

                            Icon is :
                            icon.png

                            I saw that
                            fab9ae44-410d-4834-a9be-1e2dd7f7ee05-image.png

                            @JonB said in Icon for linux application:

                            desktop file is in somewhere like ~/.local/share/applications/, right?

                            should i create .destop file in there ?

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by JonB
                            #25

                            @Joe-von-Habsburg
                            As I understand it, your icon.desktop file seems to be in some build directory. I said you should have nothing to do with build directory at runtime. What makes you think Ubuntu/GNOME will look in your build directory for any .desktop file, why should it? It does not even know it is there.

                            1. Put your icon.png in /home/joe.
                            2. Leave your icon executable in something like /home/joe/iconproject/build/Desktop/ directory. (I assume your executable is named icon.)
                            3. Ensure icon.desktop includes the following 2 lines among its other content:
                            Icon=/home/joe/icon.png
                            Exec=/home/joe/iconproject/build/Desktop/icon
                            
                            1. Put/copy icon.desktop to directory /home/joe/.local/share/applications/. That is where Ubuntu/GNOME/desktop manager looks for .desktop files. You might have some more there if you have any other applications with .desktop files, or your might be the only one.

                            You might have to log out of desktop and back in again after you have done item #4, to make GNOME look in /home/joe/.local/share/applications/ again for your new icon.desktop file.

                            When you have this working you can think again/play with lines

                            Icon=/home/joe/icon.png
                            Exec=/home/joe/iconproject/build/Desktop/icon
                            

                            so that they do not necessarily have to have /home/joe in them if you want this to run/distribute elsewhere. But first get it working with the absolute paths so we know where we are.

                            1 Reply Last reply
                            3
                            • Joe von HabsburgJ Offline
                              Joe von HabsburgJ Offline
                              Joe von Habsburg
                              wrote on last edited by
                              #26

                              Thank you so much, It works. For that kind of things, must be so explanatory. Thanks everyone :)

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved