PDA

View Full Version : Redirect printf and update progressbar



rouge
6th October 2011, 08:05
hi,
I'm training a NN with the OpenCV library. For more information's I uncommented the line 917 in the ann_mlp.cpp File:

printf("%d. E = %g\n", iter/count, E);

now the output is show in the console output.

I would like to add a progressbar and redirect the printf-ouput to a QPlainTextField.
How could I realized that? How could I update the Progressbar without too many changes in the OpenCV Library?

thx

wysota
7th October 2011, 21:22
You'd have to somehow substitute STDOUT with your own file descriptor. It's not really Qt related. Once you have that done you can read from the stream and output to a Qt widget.

ChrisW67
7th October 2011, 23:06
freopen() (http://www.cplusplus.com/reference/clibrary/cstdio/freopen/) is the one way to redirect the output to a file. There are a number of suggestions for redirecting to an in-memory buffer/stream here (http://stackoverflow.com/questions/955962/how-to-buffer-stdout-in-memory-and-write-it-from-a-dedicated-thread)