Results 1 to 15 of 15

Thread: Console replacement

  1. #1
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Console replacement

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Console replacement

    Take a look at qInstallMsgHandler()

  3. #3
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Console replacement

    Quote Originally Posted by wysota View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Console replacement

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Console replacement

    Quote Originally Posted by wysota View Post
    Alternatively make your own streaming class that inherits std:stream 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...
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Console replacement

    Quote Originally Posted by aegis View Post
    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 ?
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Console replacement

    Quote Originally Posted by fullmetalcoder View Post
    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.
    Last edited by wysota; 31st March 2007 at 23:38.

  8. #8
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Console replacement

    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/R...to-qDebug.html
    which is not what i am looking for

    thanks again for your time,
    N.A

  9. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Console replacement

    Quote Originally Posted by aegis View Post
    Forgive my english, maybe i asked the question wrong because doing some searching i found this :
    http://www.qtforum.org/article/678/R...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. 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.
    Current Qt projects : QCodeEdit, RotiDeCode

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Console replacement

    Quote Originally Posted by aegis View Post
    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.

  11. #11
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Console replacement

    There might be another reason not to use qDebug for non-debug purposes and especially not for some console replacements:

    Qt Code:
    1. Warning: The internal buffer is limited to 8192 bytes, including the '\0'-terminator.
    To copy to clipboard, switch view to plain text mode 

    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.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Console replacement

    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.

  13. #13
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Console replacement

    Quote Originally Posted by wysota View Post
    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

  14. #14
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Console replacement

    Quote Originally Posted by wysota View Post
    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.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Console replacement

    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.

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 09:45
  2. Reading from console using Qt 3.3.4
    By KrishnaKishan in forum Qt Programming
    Replies: 2
    Last Post: 13th March 2007, 10:30
  3. Portable Console Password Prompt
    By vermarajeev in forum General Programming
    Replies: 2
    Last Post: 2nd March 2007, 23:29
  4. How to run a console program "silently"?
    By fullmetalcoder in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2006, 10:03
  5. QPainter in console apps?
    By Funklord in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2006, 14:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.