PDA

View Full Version : Console replacement



aegis
31st March 2007, 19:54
hi, i had a console application, that i trasformed to gui one...

the problem is the i want the all the output that went to the console to go to "a virtual console"....

A console that appears like a dialog and the will have the same formating of the classic one...

anyone has some idea?

thanks in advance,
NA:)

wysota
31st March 2007, 20:32
Take a look at qInstallMsgHandler()

aegis
31st March 2007, 20:39
Take a look at qInstallMsgHandler()

thanks for your answer,

if understood corectly what the documentatin said{i am a newbie}...this is for printind debug messages....

but i want to print the output....

PS: in my code i have a lot of cout<<"some text \t other text \t"<<<endl.....
so i want to give to something that will behave like a console hoping that i wont need a lot of tranformations....

NA

wysota
31st March 2007, 20:51
for i in *.cpp
do
cat $i | sed -e "s/cout/qDebug()/g" > nocout/$i
done

:)

Alternatively make your own streaming class that inherits std::ostream and outputs everything using qDebug or some completely different mechanism. Then undefine cout and substitute it with your own.

fullmetalcoder
31st March 2007, 22:37
Alternatively make your own streaming class that inherits std::ostream and outputs everything using qDebug or some completely different mechanism. Then undefine cout and substitute it with your own.
Why should inheritance be used here? Wouldn't undefining cout and redefining it as "qDebug()" be enough (provided that a proper message handler is installed of course)?
Alternatively cout could be instanciated as a static QTextStream object operating on a QString (or a QIODevice) which would then be displayed... There are several possible solutions (more or less simple) but the choice of one depends on what you want to do with this output...

patrik08
31st March 2007, 23:00
hi, i had a console application, that i trasformed to gui one...

the problem is the i want the all the output that went to the console to go to "a virtual console"....

A console that appears like a dialog and the will have the same formating of the classic one...

anyone has some idea?

thanks in advance,
NA:)

i attach here the QConsole plugin from a old version from
http://sourceforge.net/projects/monkeystudio
is runnging like a cmd or bash command to compile qt file based all on qprocess ... from qt4 ... inside a qtextedit qwidget

search inside on code from other programm is like a book .... only one way can read the book.... searching by....

grep -R "function name xx" * [enter]

only linux && Mac have grep to find expression... or exist grep.exe ?

wysota
31st March 2007, 23:24
Why should inheritance be used here?
Because cout is an ostream. If you want to be fully compatible with it, it's safest to keep the base class. I think you might not even need to recompile existing code.


Wouldn't undefining cout and redefining it as "qDebug()" be enough (provided that a proper message handler is installed of course)?
Because of two reasons:
1. Obviously because qDebug() might not handle everything cout handles and you couldn't create a method that takes an ostream as an argument (for example all custom classes that implement an ostream operator)
2. You might want to use qDebug() for something else than to handle stdout. I'm not even sure if qDebug() is connected to stdout and not stderr... Besides, it's a debugging technique, whereas cout is not.


Alternatively cout could be instanciated as a static QTextStream object operating on a QString (or a QIODevice) which would then be displayed... There are several possible solutions (more or less simple) but the choice of one depends on what you want to do with this output...

Again, you couldn't use custom classes with it.

I googled around a little. Seems that subclassing ostream is not the way to go as it doesn't have any virtual methods which one could reimplement. Instead you should subclass std::streambuf and reimplement some methods (like "xsputn") and then create an ostream and pass it a pointer to an instance of your newly created class.

aegis
1st April 2007, 18:02
thank you all for your answers,

I am not sure i undrestood what you said but with qDebug i will get output to console....

What i want is widget {graphical} that will behave like console{so that i dont have to change the formating i used}...
for example something like the output window eclipse uses or the output window of visual studio 2005....

Forgive my english, maybe i asked the question wrong because doing some searching i found this :
http://www.qtforum.org/article/678/Redirecting-coutcerr-to-qDebug.html
which is not what i am looking for

thanks again for your time,
N.A

fullmetalcoder
1st April 2007, 18:15
Forgive my english, maybe i asked the question wrong because doing some searching i found this :
http://www.qtforum.org/article/678/Redirecting-coutcerr-to-qDebug.html
which is not what i am looking for

That may be actually... Indeed any output sent to qDebug(), qWarning() and qFatal() can be intercepted very easily and handled in any wanted fashion by setting a custom message handler (http://doc.trolltech.com/4.2/qtglobal.html#qInstallMsgHandler). which, having access to the widget, would be able to append all debug messages to it with the big advantage of being able to parse/filter them. :)

wysota
1st April 2007, 18:20
What i want is widget {graphical} that will behave like console{so that i dont have to change the formating i used}...
for example something like the output window eclipse uses or the output window of visual studio 2005....

Correct me if I'm wrong, but that's what we suggested... Make cout redirect its contents to a class/function you control so that you can redirect it to a widget of your choice.

Kumosan
2nd April 2007, 00:57
There might be another reason not to use qDebug for non-debug purposes and especially not for some console replacements:


Warning: The internal buffer is limited to 8192 bytes, including the '\0'-terminator.

I once got severely bitten by this restriction. Wondered why some debug output always stopped at a certain point and wasted quite some time trying to find the bug in my routines. :mad:

wysota
2nd April 2007, 01:05
I don't think you'll ever run into the trouble of filling the buffer, unless you:
a) write single messages longer than 8kB
b) use output of this application as input to another application and forget to read the input in the other application.

Anyway you should still use cout when you think about stdout and qDebug only for debugging/stderr.

aegis
2nd April 2007, 15:50
Correct me if I'm wrong, but that's what we suggested... Make cout redirect its contents to a class/function you control so that you can redirect it to a widget of your choice.

yes you are wright, the problem is that i am doing a university exercise{so it is my first semester of c++ and of course gui programming}, so is there any example i could look at...??

thanks for your answers,

N.A:)

Kumosan
2nd April 2007, 17:30
a) write single messages longer than 8kB


That's exactly what happened. An XML structure with an embedded image, which I wanted to see for debugging reasons on the console. Was easily larger than 8k.

wysota
3rd April 2007, 00:38
This shouldn't trigger the problem as newline characters act as buffer flushes which should trigger output to whatever is listening on the other end. So if anything was listening and reading data as it was coming, you shouldn't have had problems.