Results 1 to 4 of 4

Thread: Problem to run a Qt Gui application as root

  1. #1
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem to run a Qt Gui application as root

    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
    Qt Code:
    1. kdesu ./myapp
    To copy to clipboard, switch view to plain text mode 
    no window appears and the application exits. However, I can run it with
    Qt Code:
    1. su -c ./myapp
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem to run a Qt Gui application as root

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Problem to run a Qt Gui application as root

    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.

  4. #4
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem to run a Qt Gui application as root

    Thank you for your replies!

    The problem was that I cannot run the application and referring to the current directory
    Qt Code:
    1. kdesu ./myapp
    To copy to clipboard, switch view to plain text mode 

    Instead I have to specify the whole path to the application:
    Qt Code:
    1. kdesu ~/path/to/app/myapp
    To copy to clipboard, switch view to plain text mode 

    Obviously not at Qt question, sorry.


    Fredrik

Similar Threads

  1. Running an application with root privileges at Linux
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2009, 12:35
  2. label on root window
    By Corinzio in forum Qt Programming
    Replies: 0
    Last Post: 21st January 2009, 21:08
  3. Replies: 2
    Last Post: 2nd December 2008, 05:37
  4. Hide qtreewidgetitem root
    By altVis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2008, 11:24
  5. root-priviliges in application
    By bkv in forum KDE Forum
    Replies: 2
    Last Post: 29th October 2006, 18:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.