C++ 我可以在 Qt-Creator 中看到程序输出吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4171653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:42:40  来源:igfitidea点击:

Can I see the program output in Qt-Creator?

c++qtqt-creator

提问by Armen Tsirunyan

I am writing a simple OpenGL program with Qt Creator which basically creates a QGLWidget, shows it, and runs the application loop. I usually like debugging more with diagnostic messages turned on and off by preprocessor symbols that using an actual debugger and watches etc. In Qt Creator we have a tab called Application Output, but all I see there is "Starting xxx.exe. xxx.exe exited with code 0".No output from either std::coutor std::cerr. Now I know I could start my application from cmd.exe (yes, I am using Windows, love it :P) and see the output there but I wish I could see the output directly from the IDE. Is that possible? Thanks

我正在用 Qt Creator 编写一个简单的 OpenGL 程序,它基本上创建了一个 QGLWidget,显示它并运行应用程序循环。我通常更喜欢通过使用实际调试器和监视等的预处理器符号打开和关闭诊断消息来调试更多。在 Qt Creator 中,我们有一个名为Application Output的选项卡,但我看到的只是“启动 xxx.exe.xxx.exe以代码 0" 退出。std::cout或 都没有输出std::cerr。现在我知道我可以从 cmd.exe 启动我的应用程序(是的,我使用的是 Windows,喜欢它 :P)并在那里看到输出,但我希望我可以直接从 IDE 看到输出。那可能吗?谢谢

采纳答案by Frank Osterfeld

Usually the Application Outputpane works fine. Are you sure that you would see the output from cmd.exe(have you actually tried?)? It's usually turned off for UI applications to avoid console windows from popping up. Try CONFIG += console. Also check if you see qDebug() messagesin the Application Output.

通常应用程序输出窗格工作正常。你确定你会看到cmd.exe(你真的试过吗?)的输出?UI 应用程序通常会关闭它,以避免弹出控制台窗口。试试CONFIG += console。还要检查您是否在Application Output 中看到qDebug() 消息

回答by David Okwii

simply #include <QDebug>and then use qDebuginstead of coutlike

简单地 #include <QDebug>然后使用qDebug而不是cout

qDebug() << "you just clicked ok";

also this works

这也有效

#include <QTextStream>
QTextStream out(stdout);
out << "\nHello World!\n";

adding CONFIG += consolein the .pro file didn't work for me. I wonder why?

添加CONFIG += console.pro 文件对我不起作用。我想知道为什么?

i just discovered that i've to add "endl;" for cout to work like

我刚刚发现我必须添加“endl;” 让 cout 像这样工作

cout << "print this" << endl;

回答by rubenvb

Alternatively, you can check the "run in console" setting in the Project->Run options. This will open a new console window and display all console output there (if CONFIG += consoleis used of course).

或者,您可以在“项目”->“运行”选项中检查“在控制台中运行”设置。这将打开一个新的控制台窗口并在那里显示所有控制台输出(如果CONFIG += console使用的话)。

回答by DSUK

Try: Tools -> Options Under the "General" tab of "Environment" change the terminal entry from:

尝试:工具 -> 选项在“环境”的“常规”选项卡下,将终端条目从:

    x-terminal-emulator -e 

to

    xterm -e