qt printing to terminal

后端 未结 4 1948
深忆病人
深忆病人 2021-01-27 12:09

In my QT application, I want to have it so some real-time information prints in the terminal if I run the application from the terminal.

When I use printf(\"print this\"

相关标签:
4条回答
  • 2021-01-27 12:30

    You can use qDebug() << ..., qWarning() << ..., etc. Don't forget to include <QDebug>.

    Docs: QDebug

    0 讨论(0)
  • 2021-01-27 12:36

    Qt doesn't interfere with printf output. (On Windows qmake (not Qt) does, but that doesn't apply to Linux). However, consider that the buffering behavior for stdout leads to printf("print this") not being printed until the buffer is flushed. Try with e.g. fflush(stdout) or simply append a newline: printf("print this\n") to have the buffer flushed. That's not related to Qt at all though.

    0 讨论(0)
  • 2021-01-27 12:36

    You may also want to try adding CONFIG -= app_bundle to your .pro file.

    0 讨论(0)
  • 2021-01-27 12:38

    To write to stdout, you should add this CONFIG += console to your project file config and use cout of printf for your liking. qDebug prints by default to stderr. Check this topic for more info - How to print to console when using Qt

    0 讨论(0)
提交回复
热议问题