cout在QtCreator中不打印
cout does no print in QtCreator
我已经在这个论坛上看到了这个问题,但我不知道为什么提出的答案在我的情况下不起作用。所以我试着要求其他荡妇。
我刚刚让我的Qt创建者在Linux下运行。
我不明白为什么我的:
cout << "This does not appear";
qdebug进行时不在控制台中打印
qDebug() << "This appears";
这就是我的.pro文件中包含的内容:
QT += core gui
TARGET = aaa
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
IeplcModule.cpp
HEADERS += mainwindow.h
IeplcModule.h
FORMS += mainwindow.ui
#enable console
CONFIG += console
知道吗?
尝试使用:
cout << "asdf" << endl;
可能Qt设置iostream是为了只在新行刷新。
当使用CDB(Windows调试器(进行调试并不是在专用终端窗口中而是在QtCreator输出面板中运行应用程序时,std::cout/std::cerr
出现问题。qDebug之所以有效,是因为它在这种情况下有一个技巧。因此,在这种情况下,唯一的解决方案是启用"在终端中运行"选项。欲了解更多信息,请点击上面的Qt bug跟踪器链接。
STDOUT有可能重定向吗?qDebug默认打印到STDERR。
你#include <iostream>
了吗?我在代码中没有看到任何包含。我假设qdebug
和cout
非常相似。
确保在.pro
文件中启用了console
配置。即:
CONFIG += console
您可以从CMD运行此程序,它将向控制台打印一些消息:
/* Create a .pro file with this content:
QT += core gui widgets
SOURCES += main.cpp
TARGET = app
-------------------------------
Build and run commands for CMD:
> qmake -makefile
> mingw32-make
> "release/app"
*/
#ifdef _WIN32
#include <windows.h>
#endif
#include <QtCore/QFile>
#include <QtCore/QString>
#include <QtCore/QIODevice>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <iostream>
class Widget : public QWidget
{
public:
Widget()
{
setWindowTitle("My Title");
QString path("assets/text.txt");
std::cout << std::endl;
std::cout << "hello1" << std::endl;
std::cout << path.toStdString() << std::endl;
std::cout << "hello2" << std::endl;
}
};
int main(int argc, char *argv[])
{
#ifdef _WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
#endif
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}
相关文章:
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 如何将结构插入到集合中并打印集合的成员
- 在循环C++中指定字符串之后,不会打印该字符串
- 以螺旋方式打印矩阵的程序.(工作不好)
- 从控制台中删除最后打印的元素
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何仅使用对象名称打印特定于对象的成员
- 回溯C++不打印函数,因此文件
- 在一定长度后从数组中打印时缺少整数
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 在gem5中打印文件中的所有cache_blocks
- 打印数字图案
- 从 STL 优先级队列C++ (QtCreator) 打印结构
- cout在QtCreator中不打印