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. system tray icon missing when running as root

system tray icon missing when running as root

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 2.1k Views
  • 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.
  • A Offline
    A Offline
    aran
    wrote on last edited by
    #1

    Hi everybody,

    I have a tiny application that I need to have running as root (it controls a systemd service). It does not have any 'proper' window, but only lives in the system tray with context menu. If I run it as normal user, then the system tray icon shows up just fine. However, if I run it as root (typically by using kdesu), then nothing shows up in the system tray (though the application is running). I would assume that this is by design, but I also know that there are applications out there that successfully do something along these lines... What is the proper way to handle this scenario?

    Thanks,
    aran

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Quick idea: run your application as standard user and ask for the credentials when you actually need it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      0
      • C Offline
        C Offline
        Chrisw01
        wrote on last edited by Chrisw01
        #3

        Hi,

        It is typically a bad Idea to run applications with root privileges. I have a similar setup from a php Minecraft configuration script that needs to read write and execute code as other users as well as run root privileged system commands. What I did was utilized sudo to handle this. You can configure all sorts of access and privileges from within /etc/sudoers for a more automatic under hood approach. The sudoers man pages should be able to help you out in this type of setup.

        Chris--

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aran
          wrote on last edited by
          #4

          Thanks @SGaist and @Chrisw01! I now do it using sudo, it works just fine...

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Good

            Then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aran
              wrote on last edited by
              #6

              Well, I was considering that. However, the initial problem isn't actually solved, I just ended up doing it differently. So, marking it as "Solved" might be misleading to others searching for this problem...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I'd say yes and no. Having an application running permanently as root in a user session is pretty dangerous therefor having implemented it as a normal application requesting for elevated rights when needed is a better solution and solves the problem at hand even if it can be seen as a workaround for that specific part.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  aran
                  wrote on last edited by
                  #8

                  Good point, marked thread as solved...

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    Quick idea: run your application as standard user and ask for the credentials when you actually need it.

                    N Offline
                    N Offline
                    ngochm
                    wrote on last edited by
                    #9

                    @SGaist said in system tray icon missing when running as root:

                    Hi,

                    Quick idea: run your application as standard user and ask for the credentials when you actually need it.

                    Sorry for reply in such old topic but I am facing this problem too. Can you tell me how to ask for credentials/elevated rights for specifics action in qt application? I have googled around but still not clear how to do it especially for Ubuntu target OS. Can you give me some reference links, hints or keywords to search more?

                    JonBJ 1 Reply Last reply
                    0
                    • N ngochm

                      @SGaist said in system tray icon missing when running as root:

                      Hi,

                      Quick idea: run your application as standard user and ask for the credentials when you actually need it.

                      Sorry for reply in such old topic but I am facing this problem too. Can you tell me how to ask for credentials/elevated rights for specifics action in qt application? I have googled around but still not clear how to do it especially for Ubuntu target OS. Can you give me some reference links, hints or keywords to search more?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @ngochm
                      You should start by explaining exactly what it is you need to do when that requires root privilege. The best approach depends on what that is.

                      N 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @ngochm
                        You should start by explaining exactly what it is you need to do when that requires root privilege. The best approach depends on what that is.

                        N Offline
                        N Offline
                        ngochm
                        wrote on last edited by
                        #11

                        @JonB I am facing the same problem as the topic owner. When I run my application as root, my systemtray icon will not display and that is not good. My application actually do not need to be run as root. It may allow normal users to run application, see data, receive notify (via systemtray) but will require root privileged if users want to change settings via GUI. So I think @SGaist 's suggestion is perfectly fit my need and I really appreciate some references about that idea.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          What kind of settings are you thinking about ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          N 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            What kind of settings are you thinking about ?

                            N Offline
                            N Offline
                            ngochm
                            wrote on last edited by
                            #13

                            @SGaist said in system tray icon missing when running as root:

                            What kind of settings are you thinking about ?

                            Some settings may change the app behaviors and for security reason normal user can only see what the settings are but cannot change them. I know it would be better if those settings are throw away from GUI, placed in some config files and only allow root to modify. But in my case, it is a requirement to display those settings and allow users to change them if they have privileged. So I think your suggestion above "run your application as standard user and ask for the credentials when you actually need it" can solve my problem but just don't know how to implement it.

                            JonBJ 1 Reply Last reply
                            0
                            • N ngochm

                              @SGaist said in system tray icon missing when running as root:

                              What kind of settings are you thinking about ?

                              Some settings may change the app behaviors and for security reason normal user can only see what the settings are but cannot change them. I know it would be better if those settings are throw away from GUI, placed in some config files and only allow root to modify. But in my case, it is a requirement to display those settings and allow users to change them if they have privileged. So I think your suggestion above "run your application as standard user and ask for the credentials when you actually need it" can solve my problem but just don't know how to implement it.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #14

                              @ngochm
                              You do not explain what this has to do with root. You talk about "privilege". Do you actually run a some (other) process as root from your app? Do you attempt to read from/write to a file in the file system which only allows root access? Or what?

                              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