简体   繁体   English

使用Qt Creator和CMake显示命令提示符

[英]Show command prompt with Qt Creator and CMake

The dev environment in question consists of: 有问题的开发环境包括:

  • Windows 7 Windows 7的
  • MinGW (g++) MinGW(g ++)
  • CMake CMake的
  • Qt Creator Qt Creator

The problem is that Qt Creator, a lovely IDE as far as I can tell, does not display programs' command-line output. 问题是,据我所知,Qt Creator是一个可爱的IDE,它不显示程序的命令行输出。 It seems to have its own proprietary debug pane, but it doesn't give me, for example, runtime errors. 它似乎有自己的专有调试窗格,但它没有给我,例如,运行时错误。 It just tells me that the program has failed and gives me the exit code. 它只是告诉我程序失败了,并给了我退出代码。 I'm using Creator only for its C++ capabilities, and not using Qt in any way, so the proprietary pane is useless to me. 我只使用Creator来实现其C ++功能,而不是以任何方式使用Qt,因此专有窗格对我来说毫无用处。

So I ask this: Can something be done? 所以我问这个问题:可以做点什么吗? Am I missing something really, stupidly obvious like a built-in command line? 我是否真的丢失了一些东西,就像内置命令行那样愚蠢明显? Or, if not, can I at least use some filthy and/or repulsive hack to get it to display the Windows command prompt upon running a program? 或者,如果没有,我是否至少可以使用一些肮脏和/或令人厌恶的黑客来让它在运行程序时显示Windows命令提示符?

Last thing; 最后一件事; I did do some research, and found a way to edit the Qt project file to display the prompt, but... I'm using CMake, not Qt projects. 我做了一些研究,并找到了编辑Qt项目文件以显示提示的方法,但是......我正在使用CMake,而不是Qt项目。 So that doesn't answer my question. 所以这不回答我的问题。 If I can do something similar with CMakeLists.txt, that would be wonderful. 如果我可以使用CMakeLists.txt做类似的事情,那将是非常棒的。 But Google has failed me on that front, so I'm not holding out too much hope. 但谷歌在这方面让我失望,所以我并没有抱太大的希望。

EDIT: 编辑:

I'm specifically worried about runtime errors. 我特别担心运行时错误。 cout and printf are rerouted to Qt Creator's window, so that's fine. coutprintf被重新路由到Qt Creator的窗口,所以没关系。 I don't get runtime errors unless the debugger catches them, and the frequency of that is less than ideal. 除非调试器捕获它们,否则我不会遇到运行时错误,并且其频率不太理想。

Windows GUI programs don't have standard output. Windows图形用户界面程序没有标准输出。

In Windows there are two possible entry points in the standard runtime. 在Windows中,标准运行时中有两个可能的入口点。 The console one and the windows one. 控制台一个和窗户一个。 The console one will inherit console window from parent process or create a new one and connect the standard input/output/error streams to it, while the windows one will leave them unconnected unless they were explicitly redirected by the invoking process. 控制台将从父进程继承控制台窗口或创建一个新的控制台窗口并将标准输入/输出/错误流连接到它,而Windows将使它们保持未连接状态,除非它们被调用进程显式重定向。 A Qt application is (probably; you could have console Qt-Core application) a GUI application and Qt Creator (nor any other Windows IDE) does not redirect the output explicitly. Qt应用程序(可能;您可以拥有控制台Qt-Core应用程序)是一个GUI应用程序,Qt Creator(也没有任何其他Windows IDE)不会显式重定向输出。 Therefore the standard output is not open at all and the writes are being discarded. 因此,标准输出根本不打开,并且写入被丢弃。

However windows have separate logging facility for debugging purpose. 但是,Windows具有单独的日志记录功能以进行调试 This is what you see in the debug window. 这是您在调试窗口中看到的内容。 You can write to it using the native OutputDebugString API. 您可以使用本机OutputDebugString API写入它。 I am sure you can also direct the Qt debug log there. 我相信你也可以在那里指导Qt调试日志。

Note, that when it tells you the program has exited with status 0, it means the program ran, which in turn means it compiled successfully and thus there were no errors from g++. 注意,当它告诉你程序已退出状态为0时,表示程序已运行,这反过来意味着它已成功编译,因此g ++没有错误。 There may have been warnings, in which case you should see them in the appropriate other window. 可能有警告,在这种情况下,您应该在适当的其他窗口中看到它们。 Compiler and program output are different things; 编译器和程序输出是不同的东西; the IDE does read the compiler output. IDE确实读取了编译器输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM