开发者

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

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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜