Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]Slow performances with QPlainTextEdit
Forum Updated to NodeBB v4.3 + New Features

[solved]Slow performances with QPlainTextEdit

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nekkro-kvlt
    wrote on last edited by
    #1

    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:
    @void logEditor::dropEvent(QDropEvent de)
    {
    // Unpack dropped data and handle it the way you want
    const QMimeData
    mimeData = de->mimeData();

       // check for our needed mime type, here a file or a list of files
       if (mimeData->hasUrls())
       {
           QList<QUrl> urlList = mimeData->urls();
           // extract the local paths of the files
           for (int i = 0; i < urlList.size(); ++i)
           {
               QFile file&#40;urlList.at(i&#41;.toLocalFile(&#41;&#41;;
               if (!file.open (QIODevice::ReadOnly&#41;)
                    return;
    
               QTextStream stream ( &file );
               //QString line;
               setIsUpdating();
               while( !stream.atEnd() ) {
                    //line = stream.readLine();
                    this->appendPlainText(stream.readLine());
               }
               file.close(); // when your done.
               setIsUpdating(false);
           }
    
       }
    

    }@

    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 ?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      One problem is definitely that you are appending ( especially if long texts).
      It's basically adding strings together and updating it every single time when it's added.
      Try building string in background and then only show it.
      Or use insertPlaintText(QString); but it will automatically create new line.


      Code is poetry

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nekkro-kvlt
        wrote on last edited by
        #3

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

        Thanks dude !

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jake007
          wrote on last edited by
          #4

          You'r welcome :) .
          Please, mark thread as solved.

          Regards,
          Jake


          Code is poetry

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nekkro-kvlt
            wrote on last edited by
            #5

            hi,

            How do I mark as solved, should I just put [solved] in title ?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Yep :-)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved