Debug Qt application on ubuntu with root permission using qt creator

  1. Go to Tools-> Options-> Environment
  2. In the Tab General under **System** Group there is a Terminal Option.
  3. The default value is set to/usr/bin/xterm -e. Replace it with /usr/bin/xterm -e sudo or /usr/bin/gnome-terminal -x sudo.
  4. Press Apply and OK Buttons.
  5. Under Mode Selector click on Projects, select Run Option. Under Run Group Box select Run in Terminal.

Remember : sudo option must be there

Edit /etc/sudoers using sudo visudo

Next time when you run the program it will be invoked in a new xterm or gnome-terminal with Super User Permission and will ask for the root password.


I would run the program from a terminal with a GDB server (as root) and then connect to the server with gdb from QtCreator. You would start gdbserver with something like this:

$ sudo gdbserver host:2345 ./MyApp

Here, you are hosting the server with port 2345. You can also check if your application is indeed running with UID 0.

$ sudo ps -u

Now, in Qt Creator, go Debug -> Start Debugging -> Attach to Running Debug Server. Fill in the form... the most important is the port and server address. I chose 127.0.0.1 and 2345. You can select break at main to break at the beginning of the program. GDB server doesn't start the program until you connect.