KcFnMi
KcFnMi

Reputation: 6171

printf() vs qDebug() order of execution in QtCreator

Given the following calls:

printf ("Characters: %c %c \n", 'a', 65);    
qDebug() << "adcasd";

Why I see the following (inverted) output in the QtCreator Application Output?

adcasd
Characters: a A

Upvotes: 2

Views: 2374

Answers (2)

Ari Hietanen
Ari Hietanen

Reputation: 1769

printf is only flushed automatically with a new line if it can be detected to refer to an interactive device. I'm not sure what is the case here, but you could try to flush is explicitly with fflush(stdout); after the line with printf command.

Upvotes: 1

SteakOverflow
SteakOverflow

Reputation: 2033

printf() writes directly to stdout and flushes every time it hits a line break. qDebug() writes to the debugger. Qt Creator displays both in the same window (but usually in different colors), but they are two different streams. Thus the order of output can get mixed up a little.

Upvotes: 6

Related Questions