Results 1 to 6 of 6

Thread: Slow performances with QPlainTextEdit

  1. #1
    Join Date
    Feb 2012
    Posts
    10
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Slow performances with QPlainTextEdit

    Hello All,

    I'm trying to make a custom TextEditor with some cool features, but I have a show stopper here its the perf of this widget...
    I'm drag and dropping a 200Kb text file, and it takes approx 5s to load, where it's near to instantly on most of other standard text editor...

    I'm filling the widget like this:
    Qt Code:
    1. void logEditor::dropEvent(QDropEvent *de)
    2. {
    3. // Unpack dropped data and handle it the way you want
    4. const QMimeData* mimeData = de->mimeData();
    5.  
    6. // check for our needed mime type, here a file or a list of files
    7. if (mimeData->hasUrls())
    8. {
    9. QList<QUrl> urlList = mimeData->urls();
    10. // extract the local paths of the files
    11. for (int i = 0; i < urlList.size(); ++i)
    12. {
    13. QFile file(urlList.at(i).toLocalFile());
    14. if (!file.open (QIODevice::ReadOnly))
    15. return;
    16.  
    17. QTextStream stream ( &file );
    18. //QString line;
    19. setIsUpdating();
    20. while( !stream.atEnd() ) {
    21. //line = stream.readLine();
    22. this->appendPlainText(stream.readLine());
    23. }
    24. file.close(); // when your done.
    25. setIsUpdating(false);
    26. }
    27.  
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

    I have also customized a few things, but I therefore disabling all painting events while i'm filling the text, with the setIsUpdating function.
    I also even disabled all the fancy stuff to only have a QPlainTextEdit sublass with the drag and drop event and I still have this slowness.

    Full code of the editor can be seen here: http://pastebin.com/1jGtFTX8

    I don't really know why is it so slow :/

    Any ideas ?

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Slow performances with QPlainTextEdit

    You might try using QTextStream::readAll(). Heed the warning though.

    On my machine loading a 362 KB file from disk into a QPlainTextEdit took just over 1 second using readLine() and 40 ms using readAll().

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Slow performances with QPlainTextEdit

    And instead of using setIsUpdating() you could simply use QObject::blockSignals(). That has nothing to do with your original problem, just a side note.

  4. #4
    Join Date
    Feb 2012
    Posts
    10
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow performances with QPlainTextEdit

    I'm doing like this now:
    this->appendPlainText(stream.readAll());
    and it works way better

    Also, for the blockSignals, this is good to now, but I think I'll remove the isEditing function... It's been years the last time I've made C++/Qt now, so I kind of forgot the few I knew

    Thanks dudes !

  5. #5
    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: Slow performances with QPlainTextEdit

    Why are you appending line by line instead of just using setPlainText()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2012
    Posts
    10
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow performances with QPlainTextEdit

    Good Question I changed that, but I don't think this were causing trouble to append the whole doc instead of setting it... As i'm just testing for now

Similar Threads

  1. Replies: 1
    Last Post: 18th July 2011, 15:24
  2. QtableView performances
    By bacou in forum Qt Programming
    Replies: 5
    Last Post: 16th December 2010, 08:13
  3. Help with javascript performances on wince
    By lamosca in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 4th May 2010, 21:16
  4. help with QtWebkit performances
    By lamosca in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 2nd March 2010, 12:47
  5. QTableView performances
    By miraks in forum Qt Programming
    Replies: 18
    Last Post: 1st December 2008, 10:25

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.