PDA

View Full Version : Problem to run a Qt Gui application as root



holmfred
23rd October 2010, 13:37
Hello!

I have problem to run a GUI application as root in Linux. I have created a standard Qt GUI application with qtcreator and running it as a normal user works fine.

If I try to run it with the command
kdesu ./myapp no window appears and the application exits. However, I can run it with
su -c ./myapp or if a log in as root and then launch the application. I have no problem to launch e.g. kwrite with kdesu so way does my application not start?

A cannot sudo either as it complains about not being able to connect to the X server. This seams to have something to do with QApplication. QCoreApplication does not have this problem with sudo.

I just want to run the application with kdesu, way can't I do that?


Fredrik

wysota
23rd October 2010, 13:51
QCoreApplication doesn't connect to the X server at all. My guess would be that kdesu resets the environment of the shell so the process can't connect to the X server. Try running it with su - -c ./myapp and see if it works. If it doesn't then I'm probably right (the additional dash to su should clear the environment before switching users). You might also try running "xhost +" prior to switching users, this should disable access control to the X server.

SixDegrees
23rd October 2010, 13:52
A lot of Linux systems disable the X server when running as root; any applications that require it will fail. You can check: see if you can run xclock while you're logged in as root. If so, then the problem lies elsewhere.

holmfred
23rd October 2010, 14:07
Thank you for your replies!

The problem was that I cannot run the application and referring to the current directory
kdesu ./myapp

Instead I have to specify the whole path to the application:
kdesu ~/path/to/app/myapp

Obviously not at Qt question, sorry.


Fredrik