这个奇怪的问题:
我编写了一个在 QT 中编译的 OpenGL 应用程序,然后打开了一个终端,它坐在那里什么都不做。作为测试,我创建了一个新项目……默认的纯 C++ 项目。它应该:
int main(){
cout << "Hello World" << endl;
return 0;
}
但是终端打开了,什么也没发生。尝试了谷歌搜索,但没有找到任何东西。有谁知道问题可能是什么?
我曾经也有过一样的问题。打开“项目”选项卡并在“构建和运行”->“运行”中尝试从“在终端中运行”中取下标志,然后将其放回原处。它看起来很奇怪,但帮助了我。
利用
std::cerr<<
这个对我有用
试试下面的代码:
#include <QtCore/QCoreApplication>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::cout << "hello world" << std::endl;
return a.exec();
}
来自 Qt 的文档:
The QCoreApplication class provides an event loop for console Qt applications.
This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, see QApplication.