Results 1 to 7 of 7

Thread: [UNSOLVED]QPlainTextEdit / QTextEdit performance issues using set or append methods

  1. #1
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default [UNSOLVED]QPlainTextEdit / QTextEdit performance issues using set or append methods

    Gd day,

    I have read recently a topic named "QPlainTextEdit performance in Qt 4.7.0", as topic itself referred only to Qt 4.7.0 I started this one.

    We can see that author wrote
    Quote Originally Posted by Carlsberg View Post
    ...I've narrowed down by comenting stuff in my update method and it all comes to this
    Qt Code:
    1. m_viewport->setPlainText(dataBuffer);
    To copy to clipboard, switch view to plain text mode 
    After that we can read that author himself "solved" the problem.
    Quote Originally Posted by Carlsberg View Post
    Happens the same on 4.7.2. So, compiled with 4.5.1 it's lighting fast, compiled with 4.7.0 and 4.7.2 it's amazingly slow
    My case:
    Qt Code:
    1. this->appendPlainText(finalLogContents);
    To copy to clipboard, switch view to plain text mode 
    Used as recommended in documentation with
    Qt Code:
    1. setMaximumBlockCount = 80;
    To copy to clipboard, switch view to plain text mode 
    works the same as
    Qt Code:
    1. this->setPlainText(finalLogContents);
    To copy to clipboard, switch view to plain text mode 
    Text in my QPlainTextEdit is refreshed every scroll made using either
    Qt Code:
    1. QScrollBar or WheelEvent or PageDown
    To copy to clipboard, switch view to plain text mode 
    - every time call to
    Qt Code:
    1. setPlainText()
    To copy to clipboard, switch view to plain text mode 
    consumes about 40% of 2.6 GHz CPU - it is way too much. Everytime variable named
    Qt Code:
    1. finalLogContents
    To copy to clipboard, switch view to plain text mode 
    consist of 80-100 lines depending on screen resolution.
    I am thinking that maybe textChanged() SIGNAL is causing trouble - I will check it in a while with blockSignals().

    Question:
    Is there a method which use
    Qt Code:
    1. char *
    To copy to clipboard, switch view to plain text mode 
    instead of QString(I think it will be way faster cause I store all my data in
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    Should I revert to 4.5.1 or reimplement all crucial methods and create own fully customized TextEdit or maybe find another way using native QPlainTextEdit?

    Thank you in advance, please post any even strange idea!

    Edit 1:
    Unfortunately textChanged SIGNAL is not causing my problem since it is not connected to any slot thus blocking it with QObject::blockSignals() gives nothing.
    Last edited by MW; 27th July 2012 at 19:54.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit / QTextEdit performance issues using set or append methods

    We can see that author wrote...

    No, you can see. Nobody else can. Why didn't you link it?

    Have you tried text modification using QTextCursor?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit / QTextEdit performance issues using set or append methods

    Quote Originally Posted by amleto View Post
    We can see that author wrote...

    No, you can see. Nobody else can. Why didn't you link it?

    Have you tried text modification using QTextCursor?
    You are more than right, but topic is very short - this explains my attitude
    http://www.qtcentre.org/threads/3926...ce-in-Qt-4-7-0
    Regarding QTextCursor - I didn't try it - will do it in a couple of minutes.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit / QTextEdit performance issues using set or append methods

    additionally, have you made sure you are running a release build? (with the various iterator check disabling macros defined if you are using msvc and stl - yes, some are still enabled in release in studio 2005 and 2008 iirc)
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit / QTextEdit performance issues using set or append methods

    Quote Originally Posted by amleto View Post
    additionally, have you made sure you are running a release build? (with the various iterator check disabling macros defined if you are using msvc and stl - yes, some are still enabled in release in studio 2005 and 2008 iirc)
    Yes tried release build both on MinGW and MSVC 2008 using Qt 4.8.0

    Edit 1:
    Tried using QTextCursor insertText() method without any luck still big CPU usage which causes sluggish GUI.
    Pasting function which is responsible for setting text. CustomTextEdit inherits from QPlainTextEdit.

    Qt Code:
    1. void CustomLogView::updateLogViewTextCursor(const QString &finalLogContents, const bool firstUpdate)
    2. {
    3. qDebug() << "CALL -> " + CommonFunctions::getCurrentTime();
    4. //QString finalLogContents = "A";
    5.  
    6. if(firstUpdate)
    7. {
    8. this->document()->setPlainText(finalLogContents);
    9. //this->appendPlainText(finalLogContents);
    10. }
    11. else
    12. {
    13. this->document()->setPlainText(finalLogContents);
    14. QTextCursor cursor = this->textCursor();
    15. int line = getLine(cursor);
    16. int column = getIndex(cursor);
    17.  
    18. QTextBlock block = this->document()->begin();
    19. int i = 0;
    20. for( ; block != this->document()->end(); block = block.next(), ++i )
    21. {
    22. if(i == line)
    23. {
    24. cursor.setPosition(block.position() + column);
    25. break;
    26. }
    27. }
    28. this->setTextCursor(cursor);
    29. }
    30.  
    31. }
    To copy to clipboard, switch view to plain text mode 

    Edit 2:
    QTextCursor with insertText() mixed with beginBlockEdit() and endBlockEdit() gives me less sluggish GUI. Looks better, will try more fixes.

    Edit 3:
    Finally found some library code:
    Qt Code:
    1. void QTextDocument::setPlainText(const QString &text)
    2. {
    3. bool previousState = d->isUndoRedoEnabled();
    4. d->enableUndoRedo(false);
    5. d->beginEditBlock();
    6. d->clear();
    7. QTextCursor(this).insertText(text);
    8. d->endEditBlock();
    9. d->enableUndoRedo(previousState);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Using setPlainText() makes app slower (besides calling many functions in the chain) especially if you set enableUndoRedo(false).
    Will research and revert with more info.
    Last edited by MW; 27th July 2012 at 23:36.

  6. #6
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit / QTextEdit performance issues using set or append methods

    Bumping thread a little.
    Wondering if
    Qt Code:
    1. drawContents()
    To copy to clipboard, switch view to plain text mode 
    function in
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    will speed it up, anyone had experience with this?

  7. #7
    Join Date
    Oct 2012
    Location
    Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [UNSOLVED]QPlainTextEdit / QTextEdit performance issues using set or append metho

    Hi nearly the same Problem here have you found any solution so far ?

    I have a 6MB big .txt file to read wich takes several minutes to show up in PlainTextEdit.

    I think it is some kind of memory Problem which causes CPU usage to explode.

    thx in advance

Similar Threads

  1. QPlainTextEdit performance in Qt 4.7.0
    By Carlsberg in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2011, 08:57
  2. PyQt4 - QPlainTextEdit: performance when hidding blocks
    By josemaria.alkala in forum Newbie
    Replies: 6
    Last Post: 27th June 2010, 14:58
  3. QTextEdit doesn't append text
    By Luc4 in forum Qt Programming
    Replies: 7
    Last Post: 13th June 2010, 22:45
  4. margins in QTextEdit/QPlainTextEdit
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2010, 09:35
  5. QTextEdit::append help
    By tho97 in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10

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.