Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Qt Creator add a newline after cout.flush() call?

The code is simple

#include <iostream>
#include <unistd.h>
using namespace std;

int main()
{
    for(int i = 0; i < 3; ++i)
    {
        cout << "1 "; cout.flush();
        sleep(1);
    }
}

while in .pro file

QT += core    
TARGET = ProjectName    
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets    
TEMPLATE = app

If the output goes into Qt Creator "application output" (the place under source code place by default), every "1" starts from a new line.

If I compile and execute separate *.cpp file in Ubuntu Terminal using g++, it works in a proper way.

If I create a new project in Qt Creator and output goes into Qt Creator console (new window with black background), it works in a proper way.

Well, why does cout.flush() cause a newline in the first case?

like image 855
Michael Atanov Avatar asked Nov 29 '14 13:11

Michael Atanov


1 Answers

Apparently, this is a Qt Creator bug that they don't plan to resolve any time soon (at least that was the state in April, 2015). I've tested Qt Creator 3.5.1 (Qt 5.5.1) and the bug still exists, even though the new line is printed only after the first std::cout.flush() call or appending std::flush manipulator to std::cout << call.

Anyways, JIRA ticket for this bug can be found here:

Flushing application output automatically starts a new line

like image 68
dbajgoric Avatar answered Oct 04 '22 15:10

dbajgoric