[Qt-interest] How to capture stdout and redirect it to the gui?

K. Frank kfrank29.c at gmail.com
Thu Jan 27 21:27:17 CET 2011


Sergey -

Thank you for the worked-out example.

On Thu, Jan 27, 2011 at 2:13 PM, Sergey Krupov
<sergey.krupov.1 at gmail.com> wrote:
> 27.01.2011 3:42, K. Frank пишет:
>> Hello Qt!
>>
>> I would like to "capture" stdout and redirect it to a logging
>> window, for example, a QTextEdit.
>> ...
>> K. Frank
>
> Previouse example was incorrect. This one should work
>
> #include <stdlib.h>
> ...
> #include <pthread.h>
> ...
> void* thread_func(void *fd)
> {
> ...
>     int status = select (FD_SETSIZE, &set, NULL, NULL, &timeout);
> ...

As you mentioned in your original post, this is for linux.
Unfortunately, I am using windows, and, if I recall correctly,
on windows the select call only lets you use sockets, not
file descriptors.

Also, I'd prefer not to mix in pthreads.  (I do have a working
pthreads-win32 installed, but I've never tried using it together
with Qt.)

> ...
>     // writing to stderr
>     char test_string[] = "Hello from Sergey";
>     int k = write(2, test_string, sizeof(test_string));

std::cout << "Hello back at you, Sergey!";

> ...

I appreciate your suggestion.


K. Frank



More information about the Qt-interest-old mailing list