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. Starting Qt app under Linux with super user rights: QApplication style is not set!
Forum Updated to NodeBB v4.3 + New Features

Starting Qt app under Linux with super user rights: QApplication style is not set!

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 6.0k Views 1 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.
  • F Offline
    F Offline
    floatingWoods
    wrote on 23 May 2012, 13:09 last edited by
    #1

    I just discovered this, and can't explain why it is like that:

    Under Linux (Ubuntu 12.04), when I start my Qt application with "./myApp.sh", then everything looks fine (i.e. neat, the default style).
    But when I start with "sudo ./myApp.sh", the style is minimalistic it appears (i.e. it looks ugly).

    Even using "QApplication::setStyle("plastique")" in my application doesn't have any effect (when sudo is used).

    Anyone knows what is going on here?

    Thanks for any insight!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      C00l
      wrote on 31 May 2012, 12:30 last edited by
      #2

      I have noticed similar thing.
      I am using Ubuntu 10.04, Qt 4.7.4.

      user@user-desktop:~$./MyApp (Looks fine, comes up with current Desktop theme.)

      user@user-desktop:~$ sudo ./MyApp(My qt application which should have root permissions to run.) comes up with a different look.

      I need Myapp to comes up with user current theme. Dose QT provide any such feature to handle current scenario ?

      Any idea how this can be fixed .

      Please help me with your suggestions.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on 31 May 2012, 18:22 last edited by
        #3

        When using sudo the application is normally run as user root, not as the current user.

        That one most likely has themes, fonts, etc. set up and thus your application ends up using the built-in defaults. Fix the setup for root and you should be fine.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ryein
          wrote on 31 May 2012, 19:56 last edited by
          #4

          I'm not familiar with setting up root since I use a Debian based system and root is disabled. We only have sudo.

          Excuse my ignorance, but exactly would you go about setting up those defaults?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on 31 May 2012, 20:22 last edited by
            #5

            Debian has a enabled root user by default AFAIK. It is just ubuntu that does not. Sudo is just another way to make yourself root.

            You can do any of the following: Just do "xhost +" to allow anybody access to your display (use xauth instead if you are not alone on your computer!), then do "sudo su -" and you end up in a shell running root.

            Set up X windows (export DISPLAY=:0 should do the trick if it does not work without any magic) and run the system configuration utility of your desktop environment to set up the theming. For gnome/unity that should be gnome-control-center, for kde kcontrol IIRC, but I don't know for XFCE and what else you might be using;).

            Don't forget to set "xhost -" after leaving the root shell again to block others from connecting to your display.

            Note that all these settings are completely independent of what the user is actually using! You can not have root just use the theming of the user that ran sudo. Otherwise that user might be able to sneak code into root's programs (e.g. a theming engine).

            1 Reply Last reply
            0
            • I Offline
              I Offline
              iveand
              wrote on 25 Jun 2013, 21:27 last edited by
              #6

              Older thread but this is exactly my problem. I have a program that I need to start with root permissions. Something I have done to my Linux Mint 13 install makes it so it works great (launched with root by "sudo appName" matches look and feel when launched as normal user).

              However, on Ubuntu 12.04 and 13.04 test machines, I get the generic "Win 95" look when launching as sudo. I have tried dconf-editor (for root) and all the related gsettings set commands (as root) to try and set the theme, etc. So, now root's theme supposedly reports "Ambiance", but the "Win 95 look" continues. Somehow it is not being respected.

              Any help would be appreciated: users are thinking the program is shoddy (well, it may be, but at least it should look better than it does if I can get it to use the theme :-)

              1 Reply Last reply
              0
              • I Offline
                I Offline
                iveand
                wrote on 25 Jun 2013, 21:35 last edited by
                #7

                I should note that many indicate to simply link root/.themes to ~/.themes. But for me I don't have any local themes: only system themes in /usr/share/themes.

                To test I have even done this:

                cp -Rf .config/ .fontconfig/ .gconf/ .gnome2/ /root/

                In order to get root settings to match user. But still no luck (on Ubuntu 12.04 / 13.04)

                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