简体   繁体   English

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

[英]Can I see the program output in Qt-Creator?

I am writing a simple OpenGL program with Qt Creator which basically creates a QGLWidget, shows it, and runs the application loop.我正在用 Qt Creator 编写一个简单的 OpenGL 程序,它基本上创建了一个 QGLWidget,显示它并运行应用程序循环。 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".我通常更喜欢通过使用实际调试器和监视等的预处理器符号打开和关闭诊断消息来调试更多。在 Qt Creator 中,我们有一个名为Application Output的选项卡,但我看到的只是“启动 xxx.exe.xxx.exe以代码 0" 退出。 No output from either std::cout or std::cerr . std::coutstd::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.现在我知道我可以从 cmd.exe 启动我的应用程序(是的,我使用的是 Windows,喜欢它 :P)并在那里看到输出,但我希望我可以直接从 IDE 看到输出。 Is that possible?那可能吗? Thanks谢谢

Usually the Application Output pane works fine.通常应用程序输出窗格工作正常。 Are you sure that you would see the output from cmd.exe (have you actually tried?)?你确定你会看到cmd.exe的输出(你真的尝试过吗?)? It's usually turned off for UI applications to avoid console windows from popping up. UI 应用程序通常会关闭它,以避免弹出控制台窗口。 Try CONFIG += console .试试CONFIG += console Also check if you see qDebug() messages in the Application Output .还要检查您是否在Application Output 中看到qDebug() 消息

simply #include <QDebug> and then use qDebug instead of cout like只需#include <QDebug>然后使用qDebug而不是cout类的

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

also this works这也有效

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

adding CONFIG += console in the .pro file didn't work for me.在 .pro 文件中添加CONFIG += console对我不起作用。 I wonder why?我想知道为什么?

i just discovered that i've to add "endl;"我刚刚发现我必须添加“endl;” for cout to work like让 cout 像这样工作

cout << "print this" << endl;

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 += console is used of course).这将打开一个新的控制台窗口并在那里显示所有控制台输出(如果使用CONFIG += console当然)。

Try: Tools -> Options Under the "General" tab of "Environment" change the terminal entry from:尝试:工具 -> 选项在“环境”的“常规”选项卡下,将终端条目从:

    x-terminal-emulator -e 

to

    xterm -e

I know that this answer do not answer the original question, but since when searching for "No application output" we found this answer...我知道这个答案没有回答最初的问题,但是因为在搜索“无应用程序输出”时我们找到了这个答案......

See the following answer: https://stackoverflow.com/a/26325743/808101 This only apply to qDebug() and similar functions (not direct output to stdout/stderr).请参阅以下答案: https ://stackoverflow.com/a/26325743/808101 这仅适用于 qDebug() 和类似函数(不直接输出到 stdout/stderr)。 In my case, I have to set QT_ASSUME_STDERR_HAS_CONSOLE environment variable to 1 in QtCreator in order to see qDebug() messages inside "Application Output" window.就我而言,我必须在QT_ASSUME_STDERR_HAS_CONSOLE环境变量设置为1 ,以便在“应用程序输出”窗口中查看 qDebug() 消息。

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

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