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. QScintilla Reading file incremetally to avoid performance issue
Forum Updated to NodeBB v4.3 + New Features

QScintilla Reading file incremetally to avoid performance issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.8k Views 3 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I am using QScintilla , I am dumping a big file (1500 MB) line my line and the tools hangs

    if (FILE* fp = UFile::open(ofilename.toLatin1(), "r")) {
    QTextStream ts(fp, QIODevice::ReadOnly);

    •   setText(ts.readAll());
      
    •   //setText(ts.readAll());
      
    •    QString line ;
      
    •    do {
      
    •      line = ts.readLine();
      
    •        //insert(line
      
    •        append(line);
      
    •        append("\n");
      
    •     } while (!line.isNull());
        setModified(FALSE);
        UFile::close(fp);
        d_filename = ofilename;
      

    is there any way we can avoid the hang . Is there any we can ask Q Scintilla to load the file incrementally as the scroll bar moves ( how it works in gvim of Linux) where colors come down incrementatlly

    K 1 Reply Last reply
    0
    • Q Qt Enthusiast

      I am using QScintilla , I am dumping a big file (1500 MB) line my line and the tools hangs

      if (FILE* fp = UFile::open(ofilename.toLatin1(), "r")) {
      QTextStream ts(fp, QIODevice::ReadOnly);

      •   setText(ts.readAll());
        
      •   //setText(ts.readAll());
        
      •    QString line ;
        
      •    do {
        
      •      line = ts.readLine();
        
      •        //insert(line
        
      •        append(line);
        
      •        append("\n");
        
      •     } while (!line.isNull());
          setModified(FALSE);
          UFile::close(fp);
          d_filename = ofilename;
        

      is there any way we can avoid the hang . Is there any we can ask Q Scintilla to load the file incrementally as the scroll bar moves ( how it works in gvim of Linux) where colors come down incrementatlly

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Qt-Enthusiast

      See answer in your other post

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Still it is taking time can we have progress bar attached to the loading the file

        K 1 Reply Last reply
        0
        • Q Qt Enthusiast

          Still it is taking time can we have progress bar attached to the loading the file

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Qt-Enthusiast

          Here is a link to QProgressDialog i the detailed description is also an example for use.

          You can also display some sort of an increasing counter to qDebug() if you have a console window. This is probably easier for you start with.

          int count = 0; 
          do {
             line = ts.readLine();
             //insert(line
             append(line);
             append("\n");
             qDebug() << ++count; 
          }  while ( ! ts.atEnd());
          

          Also I would start with a much smaller file to see if the main instructions are working as expected. When you run your program in the debugger with debug mode it will take some time. It all depends on your patience.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            I changed the code to this now

            clock_t begin = clock();
            QFile data(ofilename.toLatin1().constData());
            QString line;
            if (data.open(QFile::ReadOnly)) {
            setText(data.readAll());
            setModified(FALSE);
            data.close();
            d_filename = ofilename;
            emit fileNameChanged(ofilename);
            }
            clock_t end = clock();
            double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
            printf("The Slow operartion took %f",elapsed_secs) ;

            and it is taking 99 seconds for a 1100 MB file . Can u sugggest

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on last edited by
              #6

              I changed the code to this now

              clock_t begin = clock();
              QFile data(ofilename.toLatin1().constData());
              QString line;
              if (data.open(QFile::ReadOnly)) {
              setText(data.readAll());
              setModified(FALSE);
              data.close();
              d_filename = ofilename;
              emit fileNameChanged(ofilename);
              }
              clock_t end = clock();
              double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
              printf("The Slow operartion took %f",elapsed_secs) ;

              and it is taking 99 seconds for a 1100 MB file . Can u suggest a better code

              K 1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi
                This is a compact as it gets.
                I dont think you can make it run faster as it must first read all 1100 mb in
                and then setText might also copy.

                1 Reply Last reply
                2
                • Q Qt Enthusiast

                  I changed the code to this now

                  clock_t begin = clock();
                  QFile data(ofilename.toLatin1().constData());
                  QString line;
                  if (data.open(QFile::ReadOnly)) {
                  setText(data.readAll());
                  setModified(FALSE);
                  data.close();
                  d_filename = ofilename;
                  emit fileNameChanged(ofilename);
                  }
                  clock_t end = clock();
                  double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
                  printf("The Slow operartion took %f",elapsed_secs) ;

                  and it is taking 99 seconds for a 1100 MB file . Can u suggest a better code

                  K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  @Qt-Enthusiast

                  You may check which part of the code is really taking time by going back to your reading line-by-line version and summing up the required time slices. Possibly setText allows some improvements. But otherwise @mrjj is correct.

                  Also you are not stating how you have compiled the source. If it is still debug mode, a release compiled version will help significantly. If it is already release you save a bit by using different compile switches for speeding up. However, you have to realize that those different switches may buy some percentage but typically not factors.

                  Finally you have to consider also your hardware, e.g. a slow disk or network might be the bottleneck.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  2
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by
                    #9

                    So as I understand the following code is the best code for this solution, as we have not incrementatl loading in Qscintilla

                    I changed the code to this now

                    clock_t begin = clock();
                    QFile data(ofilename.toLatin1().constData());
                    QString line;
                    if (data.open(QFile::ReadOnly)) {
                    setText(data.readAll());
                    setModified(FALSE);
                    data.close();
                    d_filename = ofilename;
                    emit fileNameChanged(ofilename);
                    }

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @Qt-Enthusiast said:
                      Yes as the only alternative is calling Qscintilla::append and you gain nothing by adding all lines, one by one.
                      Its not partial loading as in the end you will have loaded all anyway.

                      1 Reply Last reply
                      1

                      • Login

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