GUI program can't allocate a console in Qt's debugger

1

I have a GUI program that opens a Windows console in a separate window to display output and accept user input. My development environment is Qt 4.7.1 with mingw. The console works fine, until I try to run the program in Qt's debugger (gdb); then, although AllocConsole succeeds, and GetStdHandle appears to return a valid handle (0x000000d8), any attempt to use the handle causes Windows error 6 (invalid handle).

So I can't debug my program. Which is a pain, because it has some serious bugs. The problem may be that gdb's console prevents me opening my own console; but then why do AllocConsole and GetStdHandle succeed? I upgraded to Qt Creator 2.0.94 (Qt 4.7.1), but it didn't help. Any ideas?

Update I have found that I can debug the program by running it without the debugger, and then attaching to it from Qt. Not ideal, but better than nothing.

qt
qt4
console
gdb
asked on Stack Overflow Feb 1, 2011 by TonyK • edited Feb 2, 2011 by TonyK

1 Answer

1

Can't you use the standard output console, using CONFIG += console in the .pro file?

Hmm -- check this out:

A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, then it can call AllocConsole to create a new console or AttachConsole to attach to another console.

Can you try running FreeConsole before you create yours?

answered on Stack Overflow Oct 13, 2011 by hex4def6

User contributions licensed under CC BY-SA 3.0