Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, May 2004
redirecting stdout


Message 1 in thread

hi all,

i'm working on an application which uses some non-qt classes that send
their output to stdout (i.e. iostream and std::cout). i would like to
show this output in my qt application (sort of like a message log -
kdevelop has this kind of stdout view as well). 

i know that i could use qtextview to display my messages, but that would
require that i change all my non-qt classes to call an appropriate
function (like append(sometext)). so the question is, what is the best
way to redirect stdout to some qt widget, and which widget should i use.

thanks for the information.

matthias


Message 2 in thread

On Thu, May 06, 2004 at 02:54:15PM +0200, Matthias Schweinoch wrote:
} i'm working on an application which uses some non-qt classes that send
} their output to stdout (i.e. iostream and std::cout). i would like to
} show this output in my qt application (sort of like a message log -
} kdevelop has this kind of stdout view as well). 
} 
} i know that i could use qtextview to display my messages, but that would
} require that i change all my non-qt classes to call an appropriate
} function (like append(sometext)). so the question is, what is the best
} way to redirect stdout to some qt widget, and which widget should i use.

There is no platform-independent way of doing this, as far as I know.
For Unix and Unix-like systems (i.e. anything but Windows) you can use
Posix APIs to do what you want. Look into dup2() and either pipe() or
socketpair(). (I'm told socketpair() is preferable to pipe(), but I've
only used pipe() myself.) Recall that stdout is file descriptor 0, and
bound to it by number rather than anything deeper; if you make fd 0
point to something else (e.g. a pipe you can read), stdout goes there.

} thanks for the information.
} matthias
--Greg


Message 3 in thread

Hi,

I think this helps:
http://www.qtforum.org/thread.php?threadid=678


Am Donnerstag, 6. Mai 2004 14:54 schrieb Matthias Schweinoch:
> hi all,
> 
> i'm working on an application which uses some non-qt classes that send
> their output to stdout (i.e. iostream and std::cout). i would like to
> show this output in my qt application (sort of like a message log -
> kdevelop has this kind of stdout view as well). 
> 
> i know that i could use qtextview to display my messages, but that would
> require that i change all my non-qt classes to call an appropriate
> function (like append(sometext)). so the question is, what is the best
> way to redirect stdout to some qt widget, and which widget should i use.
> 
> thanks for the information.
> 
> matthias
> 
> --
> List archive and information: http://lists.trolltech.com/qt-interest/
> 


Message 4 in thread

>I think this helps:
>http://www.qtforum.org/thread.php?threadid=678

That's my code. Let me know if you have any questions.

Note the current code outputs to qDebug - you could add additional logging 
or output to a text widget at the same point.


Message 5 in thread

hi,

thanks for the help - i'll give it a try.. first results don't look too
pleasing, though: it would seem that debian woody's gcc (2.95.4) has
some non-compliancies with the c++ standard; it's missing streambuf, but
streambuf.h is there. replacing this in qdebug.h just gives me more
errors... but, like i said, i'll keep trying:)

matthias

On Thu, 06 May 2004 10:49:27 -0500
Paul Miller <paul@fxtech.com> wrote:

> >I think this helps:
> >http://www.qtforum.org/thread.php?threadid=678
> 
> That's my code. Let me know if you have any questions.
> 
> Note the current code outputs to qDebug - you could add additional
> logging or output to a text widget at the same point.
> 
> --
> List archive and information: http://lists.trolltech.com/qt-interest/
> 


Message 6 in thread

>thanks for the help - i'll give it a try.. first results don't look too
>pleasing, though: it would seem that debian woody's gcc (2.95.4) has
>some non-compliancies with the c++ standard; it's missing streambuf, but
>streambuf.h is there. replacing this in qdebug.h just gives me more
>errors... but, like i said, i'll keep trying:)

That's a shame that it has a non-standard C++ standard library. Surely 
there is a compliant one though available.


Message 7 in thread

On May 6, 2004 10:54 am, Matthias Schweinoch wrote:
> hi,
>
> thanks for the help - i'll give it a try.. first results don't look too
> pleasing, though: it would seem that debian woody's gcc (2.95.4) has
> some non-compliancies with the c++ standard; it's missing streambuf, but
> streambuf.h is there. replacing this in qdebug.h just gives me more
> errors... but, like i said, i'll keep trying:)

Yes, the ISO-standard (mostly, anyway) C++ libraries were introduced in the 
gcc 3.x time frame.  gcc 2.95 is really really old now, first released almost 
five years ago.

-- 
 [ signature omitted ] 

Message 8 in thread

Matthias Schweinoch wrote:

>hi all,
>
>i'm working on an application which uses some non-qt classes that send
>their output to stdout (i.e. iostream and std::cout). i would like to
>show this output in my qt application (sort of like a message log -
>kdevelop has this kind of stdout view as well). 
>
>i know that i could use qtextview to display my messages, but that would
>require that i change all my non-qt classes to call an appropriate
>function (like append(sometext)). so the question is, what is the best
>way to redirect stdout to some qt widget, and which widget should i use.
>
You'd need to write your own stream buffer that takes the data you send 
it and outputs
it to some widget (e.g. a qtextview as you say). Then you can do 
something like:

ostream myWidget;
streambuf *oldbuf = cout.rdbuf(myWidget.rdbuf()); // output now goes to 
myWidget

Take a look at p639 of Josuttis for more details.

- Keith