May 23, 2012

floatingWoods floatingWoods
Lab Rat
53 posts

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

 

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!

4 replies

May 31, 2012

C00l C00l
Lab Rat
2 posts

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.

May 31, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3155 posts

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.

May 31, 2012

Ryein Ryein
Lab Rat
4 posts

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?

May 31, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3155 posts

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).

 
  ‹‹ Mixing C and C++/Qt code      help in qml ››

You must log in to post a reply. Not a member yet? Register here!