qDebug and cout don't work

后端 未结 2 1154
我寻月下人不归
我寻月下人不归 2021-01-20 02:11

I have this simple code

#include 
#include 
#include 
using namespace std;

int main(         


        
相关标签:
2条回答
  • 2021-01-20 03:07

    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:

    • Use an application such as an IDE or standalone DebugView tool from Microsoft.
    • Use qInstallMessageHandler Qt function in your program code, and catch the debug output, and do what you want with it, such as print it with cout and/or log it.
    0 讨论(0)
  • 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";
    
    0 讨论(0)
提交回复
热议问题