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. Viewing huge files with a Qt app

Viewing huge files with a Qt app

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 3 Posters 2.6k Views
  • 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.
  • deisikD Offline
    deisikD Offline
    deisik
    wrote on last edited by
    #1

    What should I use to view huge files such as logs with their size over 1Gb (no editing required)?

    QTextEdit is useless for anything larger than a few MBs

    JonBJ 1 Reply Last reply
    0
    • deisikD deisik

      What should I use to view huge files such as logs with their size over 1Gb (no editing required)?

      QTextEdit is useless for anything larger than a few MBs

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @deisik
      Use QPlainTextEdit. If required, implement a "dynamic scrolling" mechanism which only reads further blocks from the file when the user scrolls down the document (or searches). If memory consumption must be limited, dispose earlier blocks previously read.

      Something like https://stackoverflow.com/questions/57457371/load-huge-text-buffer-into-qplaintextedit (even maybe https://interest.qt-project.narkive.com/Z1XhnVtv/qtextedit-is-too-slow-hints-needed) or other Google results for qplaintextedit large file may be of interest.

      deisikD 1 Reply Last reply
      2
      • JonBJ JonB

        @deisik
        Use QPlainTextEdit. If required, implement a "dynamic scrolling" mechanism which only reads further blocks from the file when the user scrolls down the document (or searches). If memory consumption must be limited, dispose earlier blocks previously read.

        Something like https://stackoverflow.com/questions/57457371/load-huge-text-buffer-into-qplaintextedit (even maybe https://interest.qt-project.narkive.com/Z1XhnVtv/qtextedit-is-too-slow-hints-needed) or other Google results for qplaintextedit large file may be of interest.

        deisikD Offline
        deisikD Offline
        deisik
        wrote on last edited by deisik
        #3

        Wouldn't QPlainText be even better (without editing)? Is there such a thing?

        JonBJ 1 Reply Last reply
        0
        • deisikD deisik

          Wouldn't QPlainText be even better (without editing)? Is there such a thing?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @deisik
          Don't know what you asking. I pointed you to QPlainTextEdit (which you can set readonly if you wish). If you mean is there a class QPlainText then you can discover for yourself there is not by searching the documentation/Googling.

          deisikD 1 Reply Last reply
          0
          • JonBJ JonB

            @deisik
            Don't know what you asking. I pointed you to QPlainTextEdit (which you can set readonly if you wish). If you mean is there a class QPlainText then you can discover for yourself there is not by searching the documentation/Googling.

            deisikD Offline
            deisikD Offline
            deisik
            wrote on last edited by deisik
            #5

            As far as I'm familiar with QTextEdit, you have first to "select" a part of the text in order to remove it programmatically

            This feels cumbersome to me, so I wondered if there's a parent class with which you can do stuff like this in a more direct way

            SGaistS 1 Reply Last reply
            0
            • deisikD deisik

              As far as I'm familiar with QTextEdit, you have first to "select" a part of the text in order to remove it programmatically

              This feels cumbersome to me, so I wondered if there's a parent class with which you can do stuff like this in a more direct way

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Do you mean something like QTextDocument ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              deisikD 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Do you mean something like QTextDocument ?

                deisikD Offline
                deisikD Offline
                deisik
                wrote on last edited by
                #7

                @SGaist

                Can it handle a 1GB log file?

                SGaistS 1 Reply Last reply
                0
                • deisikD deisik

                  @SGaist

                  Can it handle a 1GB log file?

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @deisik it's the underpinning of the QTextEdit and QPlainTextEdit classes.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  deisikD 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @deisik it's the underpinning of the QTextEdit and QPlainTextEdit classes.

                    deisikD Offline
                    deisikD Offline
                    deisik
                    wrote on last edited by deisik
                    #9

                    @SGaist

                    So it all comes down to dynamic loading and unloading data. I'm looking for something as simple and easy as adding/removing a row in a table

                    SGaistS 1 Reply Last reply
                    0
                    • deisikD deisik

                      @SGaist

                      So it all comes down to dynamic loading and unloading data. I'm looking for something as simple and easy as adding/removing a row in a table

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      In that case, one thing you can consider is using the model view paradigm to show your file so you can use a QListView to show each line of your file.
                      You can either load your whole file as a QStringListModel but it will likely be too slow for your needs. Or create your own model that will have a certain amount of lines in memory to show and scroll and will load/unload what needed when the user scrolls.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      deisikD 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        In that case, one thing you can consider is using the model view paradigm to show your file so you can use a QListView to show each line of your file.
                        You can either load your whole file as a QStringListModel but it will likely be too slow for your needs. Or create your own model that will have a certain amount of lines in memory to show and scroll and will load/unload what needed when the user scrolls.

                        deisikD Offline
                        deisikD Offline
                        deisik
                        wrote on last edited by deisik
                        #11

                        @SGaist

                        The problem with QListView (or QTableView, for that matter) is that you won't be able to select text across multiple lines (rows) in a regular way like with QTextEdit

                        JonBJ 1 Reply Last reply
                        0
                        • deisikD deisik

                          @SGaist

                          The problem with QListView (or QTableView, for that matter) is that you won't be able to select text across multiple lines (rows) in a regular way like with QTextEdit

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @deisik
                          As suggested, why don't you at least try the QPlainTextEdit way?

                          deisikD 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @deisik
                            As suggested, why don't you at least try the QPlainTextEdit way?

                            deisikD Offline
                            deisikD Offline
                            deisik
                            wrote on last edited by
                            #13

                            @JonB

                            It didn't change much, if anything at all. Tried to open a 90Mb file and had to euthanize it

                            JonBJ 1 Reply Last reply
                            0
                            • deisikD deisik

                              @JonB

                              It didn't change much, if anything at all. Tried to open a 90Mb file and had to euthanize it

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #14

                              @deisik
                              Then as previously suggested you probably need to read only a portion of the file into memory for display and handle scrolling programmatically. Which is the same principle if you used a model.

                              Old thread on this forum https://forum.qt.io/topic/4519/how-do-i-open-large-file-on-qtextedit seems to indicate this kind of approach.

                              BTW: for your 90MB, was it taking a long time on reading the data from file (should not be) or on displaying it in the QPlainTextEdit on screen?

                              deisikD 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @deisik
                                Then as previously suggested you probably need to read only a portion of the file into memory for display and handle scrolling programmatically. Which is the same principle if you used a model.

                                Old thread on this forum https://forum.qt.io/topic/4519/how-do-i-open-large-file-on-qtextedit seems to indicate this kind of approach.

                                BTW: for your 90MB, was it taking a long time on reading the data from file (should not be) or on displaying it in the QPlainTextEdit on screen?

                                deisikD Offline
                                deisikD Offline
                                deisik
                                wrote on last edited by
                                #15

                                @JonB

                                It freezes reading, not displaying. Actually, it doesn't freeze, but will likely take a couple hours to process the file contents

                                It is not the part about reading a portion of the file which is cumbersome, it is the part where you have to select the text programmatically to erase it which just doesn't feel right

                                JonBJ 1 Reply Last reply
                                0
                                • deisikD deisik

                                  @JonB

                                  It freezes reading, not displaying. Actually, it doesn't freeze, but will likely take a couple hours to process the file contents

                                  It is not the part about reading a portion of the file which is cumbersome, it is the part where you have to select the text programmatically to erase it which just doesn't feel right

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #16

                                  @deisik
                                  You are big on "things don't feel right" when they seem fine to me :)

                                  BTW if you have some inbuilt aversion to "using the cursor" to delete/insert, you don't have to. Just re-use setPlainText() to set the whole of the document to the newly calculated range. I don't know, but in practice this may be just as fast as using the cursor. Also BTW you could try just putting the text in a QLabel (probably wrapped in a scroll area), that does not use a cursor. You have to set the complete text, there is no insert/remove.

                                  I suggest there is something wrong if your file reading code "takes a couple of hours" to read in 90MB, don't you think...? It should take like, I don't know, a few seconds.... This is fundamental no matter which approach you take to display it.

                                  deisikD 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @deisik
                                    You are big on "things don't feel right" when they seem fine to me :)

                                    BTW if you have some inbuilt aversion to "using the cursor" to delete/insert, you don't have to. Just re-use setPlainText() to set the whole of the document to the newly calculated range. I don't know, but in practice this may be just as fast as using the cursor. Also BTW you could try just putting the text in a QLabel (probably wrapped in a scroll area), that does not use a cursor. You have to set the complete text, there is no insert/remove.

                                    I suggest there is something wrong if your file reading code "takes a couple of hours" to read in 90MB, don't you think...? It should take like, I don't know, a few seconds.... This is fundamental no matter which approach you take to display it.

                                    deisikD Offline
                                    deisikD Offline
                                    deisik
                                    wrote on last edited by deisik
                                    #17

                                    @JonB said in Viewing huge files with a Qt app:

                                    @deisik
                                    You are big on "things don't feel right" when they seem fine to me :)

                                    BTW if you have some inbuilt aversion to "using the cursor" to delete/insert, you don't have to. Just re-use setPlainText() to set the whole of the document to the newly calculated range. I don't know, but in practice this may be just as fast as using the cursor. Also BTW you could try just putting the text in a QLabel (probably wrapped in a scroll area), that does not use a cursor. You have to set the complete text, there is no insert/remove.

                                    I'm thinking about it. QLabel is probably the way to go. How can I make it look like a QTextEdit widget?

                                    I suggest there is something wrong if your file reading code "takes a couple of hours" to read in 90MB, don't you think...? It should take like, I don't know, a few seconds.... This is fundamental no matter which approach you take to display it.

                                    I have to parse the file (at least, would have the part to display)

                                    And while we are at it, just switching to a tab (window) containing a big enough QTextEdit object takes a few minutes

                                    JonBJ 1 Reply Last reply
                                    0
                                    • deisikD deisik

                                      @JonB said in Viewing huge files with a Qt app:

                                      @deisik
                                      You are big on "things don't feel right" when they seem fine to me :)

                                      BTW if you have some inbuilt aversion to "using the cursor" to delete/insert, you don't have to. Just re-use setPlainText() to set the whole of the document to the newly calculated range. I don't know, but in practice this may be just as fast as using the cursor. Also BTW you could try just putting the text in a QLabel (probably wrapped in a scroll area), that does not use a cursor. You have to set the complete text, there is no insert/remove.

                                      I'm thinking about it. QLabel is probably the way to go. How can I make it look like a QTextEdit widget?

                                      I suggest there is something wrong if your file reading code "takes a couple of hours" to read in 90MB, don't you think...? It should take like, I don't know, a few seconds.... This is fundamental no matter which approach you take to display it.

                                      I have to parse the file (at least, would have the part to display)

                                      And while we are at it, just switching to a tab (window) containing a big enough QTextEdit object takes a few minutes

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by
                                      #18

                                      @deisik said in Viewing huge files with a Qt app:

                                      I have to parse the file (at least, would have the part to display)

                                      Sorry, but if whatever parsing you do on a 90MB file takes "a couple of hours" as you state, or even if that's on 1GB, something is not right.

                                      just switching to a tab (window) containing a big enough QTextEdit object takes a few minutes

                                      Which is why you should use a QPlainTextEdit not a QTextEdit. Your timing may be affected by options, for example word wrap mode.

                                      deisikD 1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @deisik said in Viewing huge files with a Qt app:

                                        I have to parse the file (at least, would have the part to display)

                                        Sorry, but if whatever parsing you do on a 90MB file takes "a couple of hours" as you state, or even if that's on 1GB, something is not right.

                                        just switching to a tab (window) containing a big enough QTextEdit object takes a few minutes

                                        Which is why you should use a QPlainTextEdit not a QTextEdit. Your timing may be affected by options, for example word wrap mode.

                                        deisikD Offline
                                        deisikD Offline
                                        deisik
                                        wrote on last edited by deisik
                                        #19

                                        @JonB said in Viewing huge files with a Qt app:

                                        @deisik said in Viewing huge files with a Qt app:

                                        I have to parse the file (at least, would have the part to display)

                                        Sorry, but if whatever parsing you do on a 90MB file takes "a couple of hours" as you state, or even if that's on 1GB, something is not right

                                        I assume that it would take a couple of hours or so. I need real time

                                        Anyway, why don't you try it out and check for yourself?

                                        JonBJ 1 Reply Last reply
                                        0
                                        • deisikD deisik

                                          @JonB said in Viewing huge files with a Qt app:

                                          @deisik said in Viewing huge files with a Qt app:

                                          I have to parse the file (at least, would have the part to display)

                                          Sorry, but if whatever parsing you do on a 90MB file takes "a couple of hours" as you state, or even if that's on 1GB, something is not right

                                          I assume that it would take a couple of hours or so. I need real time

                                          Anyway, why don't you try it out and check for yourself?

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by JonB
                                          #20

                                          @deisik
                                          You think it would take a couple of hours to do your parsing on a 90MB/1GB file?!

                                          Anyway, why don't you try it out and check for yourself?

                                          Sorry, you would like me to write and test what you want? Not to mention, without even knowing what your "parsing" entails? That's not how it works: YOU can "try it out and check for yourself?" since it's your issue, not me.

                                          deisikD 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