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
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.
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).
You must log in to post a reply. Not a member yet? Register here!


