Debugging Ncurses applications with QT Creator

Today I stumbled over the problems while toying around with a small C project using the Ncurses library.

I recently discovered QT Creator as a decent IDE so I started to use it.

Problem 1 with running the application at all

The program builds fine and runs with ncurses if run in a seperate terminal window.
Upon run from within QT-Creator with checkmark “run in terminal” I got this error message: “Error opening terminal: unknown

After quite some googling I found the solution as the environment passed to my application in this way does not define the TERM environment variable.

So I added the definition “TERM=xterm” to the list of passed environment variables. Now the Ncurses application runs in its own terminal window.

Problem 2 with debugging the application

Naturally I do not only want to run my application, I also want to debug it using gdb. QT creator handles this normally fine so I click on “Debug.”
I see the extra terminal window opening but I get a small notice “ptrace: Operation not permitted” and all collapses.

Some more googling and I discover that Ubuntu  10.04 and later deactivate the option to attach gdb to running processes. This is something QT Creator seems to try here when running the application inside the terminal window.
I simply used the directions found here at AskUbuntu and now it works. I have the application ruuning in a seperate terminal window and I can trace, singlestep and debug it with the gdb frontend from QT Creator.

What a mess!

But it only affects debugging Ncurses and maybe S-lang projects. Normal terminal output is fine and so should be SDL based stuff aswell. It is dirty and slight hacky, but all in all it is working.