qDebug和cout不起作用 [英] qDebug and cout don't work

查看:471
本文介绍了qDebug和cout不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的代码

#include <QtCore/qdebug.h>
#include <QtCore/qcoreapplication.h>
#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
    cout << "pluto" << endl;
    QCoreApplication app(argc, argv);
    qDebug() << "pippo" << endl;
    return app.exec();
    //return 0;
}

我在Eclipse中用MinGw编译它没有任何错误,但是当我运行代码中没有字符串消息出现在控制台上。哪里不对?谢谢。

I compiled it with MinGw in Eclipse with no errors, but when I run the code no string message appear on the consolle. What is wrong? Thanks.

Luca

推荐答案

对于 cout 在Windows上工作,您需要具有 .pro 文件中的nofollow> CONFIG + =控制台 。它不应该对任何其他平台有任何影响,所以你可以把它添加到那里。您可以使用qmake条件,如果您只想要调试版本或某些东西,或者您可以将其传递给qmake作为命令行选项,如果它更方便您的工作流程:

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



在Windows下, qDebug()默认情况下输出到Windows调试日志。您可以通过两种方式获得它:


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.

这篇关于qDebug和cout不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆