Results 1 to 4 of 4

Thread: QTextEdit from cout stream not displayed at once

  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb QTextEdit from cout stream not displayed at once

    Dear all,
    I search in the web and I found out that a way to redirect std::cout to a QTextEditor is to implement a class
    Qt Code:
    1. class QDebugStream : public std::basic_streambuf<char>
    To copy to clipboard, switch view to plain text mode 
    The implementation of the class is in the attached file.
    I made the call of the class in this way (Ui_outputView I designed myself through qtDesigner, it is just a Widget containing a QTextEditor "consoleTextEdit")
    Qt Code:
    1. class OutputView : public QWidget, private Ui_outputView
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. OutputView(QWidget* parent = NULL){
    7. setupUi(this);
    8. consoleTextEdit->toPlainText();
    9. qout = new QDebugStream(std::cout, consoleTextEdit);
    10. }
    11. ~OutputView(){}
    12.  
    13. private:
    14. QDebugStream *qout;
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    The code works fine, I can display the output text but I have two main questions:
    1- I would like that the text is displayed not all at once: so far the text is displayed when the function that contains all the prints "cout<<" returns. I would like to see the output as in happen in the console when the cout is called.
    2- is it worth perhaps to use QTextStream to catch the standard output and display it in a QTextEdit? Any hints on how to do that?

    Thanks in advance for your help, if something is not clear please let me know.
    Regards,
    Annalisa
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit from cout stream not displayed at once

    Dear, the problem is getting serious now that the code takes several minutes to run the calculation.... I have the GUI in stand-by for several minutes, I would like to display the std::cout in the QTextEditor as a stream during the calculation and not all at once at the end as it is now.... is it a problem of repaint?

    PLEASE HELP!!!

    Annalisa

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTextEdit from cout stream not displayed at once

    Did you try implementing
    Qt Code:
    1. virtual std::basic_streambuf::sync();
    To copy to clipboard, switch view to plain text mode 
    in QDebugStream class?

  4. #4
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit from cout stream not displayed at once

    Hi!

    Thanks for your answer.
    I looked a bit in the web regarding the hint you gave me and I learnt a lot about streams this evening!!!

    Btw I think I found a simple way of solving my problem, I just add the line

    QCoreApplication:rocessEvents();

    every time log_window->append(...) is called inside QDebugStream. I found the solution on this useful link
    http://www.qtcentre.org/wiki/index.p...GUI_Responsive
    it as drwbacks for multithread application but so far I think is an easy solution for my problem and I don't have to deal with multithread! and most important: IT WORKS

    Thanks a lot again for your time and your help!
    If you have any further comment on the problem please let me know

    Regards
    Annalisa

    Q
    CoreApplication::ProcessEvents();
    I wrote it in the wrong format ...

Similar Threads

  1. Qt Creator where is cout in Qt Creator
    By hqking1988 in forum Qt Tools
    Replies: 8
    Last Post: 12th September 2019, 23:32
  2. where is cout
    By hqking1988 in forum General Programming
    Replies: 3
    Last Post: 22nd August 2010, 04:35
  3. Replies: 4
    Last Post: 27th March 2008, 10:21
  4. cout problem
    By mickey in forum General Programming
    Replies: 3
    Last Post: 2nd March 2007, 19:12
  5. How to cout in Qt ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2006, 01:47

Tags for this Thread

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.