Forward stdout to file in Qt application

I have a Qt application that launches several children QProcessand then calls QProcess::setChannelMode(QProcess::ForwardedChannels). I would then like to pass the stdout of this application (now containing the stdout of its children) to a log file whose location is determined by the application, which means that I cannot just change my log to also write to the specified file, because this will not work for children, and I can’t start app | tee logfilebecause I don’t know what to turn to.

I would prefer - if it exists (and I could not find it if he did) - a method for doing this through Qt, but other solutions would be acceptable.

+3
source share
3 answers

. , Qt, , freopen , :

#include <cstdio>
...
QString logFile;
...
freopen(logFile.toLocal8Bit().data(), "w", stdout);
+1

QProcess:: setStandardOutputFile()?

, .

+3

The way to do this is to change the basic one streambuf, as in this rather simple example: http://www.cplusplus.com/reference/iostream/ios/rdbuf/

may not be the best way, but he is doing his job.

+1
source

Source: https://habr.com/ru/post/1791012/


All Articles