qDebug and cout don't work

做~自己de王妃 提交于 2019-12-01 22:25:53

For cout to work on Windows, you need to have CONFIG+=console in the .pro file. It shouldn't have any effect on any other platform, so you can just add it there. You can use qmake conditionals if you only want it for debug builds or something., or you can pass it to qmake as command line option, if it is more convenient for your workflow:

qmake ...other args... CONFIG+=console

Under Windows, qDebug() output by default goes to Windows debug logs. You can get it in two ways:

If you really need have that on output, you can try with QTextSteam:

#include <QTextStream>

QTextStream cout(stdout);
cout << "string\n";

QTextSteam cerr(stderr);
cerr << "error!\n";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!