Problem with std::cout and ofLog when using QT [SOLVED]


this is kind of similar to this 6 year old thread run an openFrameworks app from a terminal and no cout <<.

I’ve been using oF v0.8.4 with Code::Blocks on Win7 and I had no problem writing:
std::cout << "foo\n";
and getting immediate output.

Now that I’ve switched to oF v0.9.3 with QT, this won’t show anything in the console (QT creator’s Application Ouput) until I close the program - unless I flush the buffer with either endl or std::cout.flush();
This is not the case when I write a plain c++ console app (without oF), only for oF apps.

To make things more complicated:
ofLog() doesn’t flush the buffer either! So I have to write
ofLog(OF_LOG_NOTICE, "foo"); std::cout.flush();
to make it work.

‘ofLogNotice() << “foo”;’

Also, if I check “run in terminal” in QT creator’s project settings, I don’t get any output, neither in the terminal, nor in the Application Output window, even when I flush the buffer.

For plain c++ console apps, cout is definitely unbuffered and output is printed to the terminal and not to Application Output. Anyone knowing more about cout and ofLog behaviour with recent QT?

I’ve found the solution myself and I hope it can be helpful for others:

It’s not enough to check “run in terminal” in the Project Settings, you also have to add a line in the qbs-File:

property string of_root: “…/…/…”

ofApp {
    name: { return FileInfo.baseName(path) }
    files: [
    consoleApplication: true // add this line to get a working terminal on windows!!!
    of.addons: [

It also makes sure the terminal pops up when you run the .exe from outside QT creator. Also, terminal output is not buffered.
Maybe this info can be added to oF + QT Windows installation guide!

sure it would also be great to add it in the template so the console appears by default. do you want to send a fix?

Hi Arturo, thanks for stepping in!

Where shall I send the fix? Actually it’s really simple:
I had a look at ofApp.qbs in [OF_DIR]/libs/openFrameworksCompiled/projects/qtcreator
and found that in line 10 it says:

consoleApplication: false

By changing it to ‘true’, the Windows terminal is enabled by default for all OF projects - unless the setting is overwritten in the project file.

I also tried to add this line in the QtCreator template (qtcreator.qbs) as you suggested, but this only works for newly created projects. However, the advantage is that the setting is visible in the project file and therefore more likely to be seen by the user. They can set it back to ‘false’ if they want their final .exe without a terminal. For a fix in the OF release this could be a good solution.

I also think ofApp.qbs could be somehow mentioned in the installation guide as a way to manually change how OF projects are setup by default. For example, I had an annoying problem with a certain dll (libstdc+±6.dll) which can’t be found via the system path because of some conflicts. Eventually I added some code in ofApp.qbs to automatically copy this dll (which I’ve put into the export folder) into the bin for every project (the same way fmodex.dll gets copied).