GUI程序不能在Qt的调试器中分配控制台 [英] GUI program can't allocate a console in Qt's debugger

查看:208
本文介绍了GUI程序不能在Qt的调试器中分配控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GUI程序,在单独的窗口中打开Windows控制台以显示输出并接受用户输入。我的开发环境是Qt 4.7.1与mingw。控制台工作正常,直到我尝试在Qt的调试器(gdb)中运行程序;然后,虽然AllocConsole成功,并且GetStdHandle似乎返回一个有效的句柄(0x000000d8),任何尝试使用该句柄导致Windows错误6(无效句柄)。

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).

所以我无法调试我的程序。这是一个痛苦,因为它有一些严重的bug。问题可能是gdb的控制台阻止我打开我自己的控制台;但是为什么AllocConsole和GetStdHandle成功了?我升级到Qt Creator 2.0.94(Qt 4.7.1),但它没有帮助。任何想法?

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?

更新我发现我可以通过运行它没有调试器,然后附加到它从Qt调试程序。

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.

推荐答案

不能使用标准输出控制台,使用
CONFIG + = console
在.pro文件中?

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

Hmm - 检查 this out:

Hmm -- check this out:


一个进程只能与一个控制台相关联,因此如果调用进程已有控制台,AllocConsole函数将失败。一个进程可以使用FreeConsole函数将它自己从它当前的控制台分离,然后它可以调用AllocConsole创建一个新的控制台或AttachConsole来附加到另一个控制台。

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.

您可以尝试在创建您的FreeConsole之前运行FreeConsole吗?

Can you try running FreeConsole before you create yours?

这篇关于GUI程序不能在Qt的调试器中分配控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆