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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With