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. If we have large text file, which class object we can use to store all the contents of the file temporarily?
QtWS25 Last Chance

If we have large text file, which class object we can use to store all the contents of the file temporarily?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 4.2k 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    Suppose my code is @
    QFile file(":/file");
    file.open (QIODevice::ReadOnly);
    ? = file.readAll ();
    @

    Pratik Agrawal

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      QByteArray , i suppose.


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        any text compatible container class will do more or less, different containers have different functionality, suitable for different usage scenarios, which you didn't specify

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on last edited by
          #4

          or you can use "QTemporaryFile":http://doc.qt.nokia.com/latest/qtemporaryfile.html


          Declaration of (Platform) independence.

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

            "store"? Store where? In memory? On disc? On the cloud perhaps?
            And what is "temporarily"? For the runtime of your application, or for some longer period of time?

            Judging by your code fragment, I think you want to store the contents in-memory. Question is: why? The file is probably not going anywhere in the meantime, so why do want to keep all its (large) contents into memory? If you really need to, I guess QByteArray is the most efficient class to do it with. At least it won't use UTF-16 if the original file was ASCII or UTF-8 or some other 8-bit encoding. That should save you memory.

            Another side note is: you already have the file in memory, because you are reading from a resource. Why do you insist in keeping another copy of the same file in memory too?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pratik041
              wrote on last edited by
              #6

              [quote author="Andre" date="1323250299"]"store"? Store where? In memory? On disc? On the cloud perhaps?
              And what is "temporarily"? For the runtime of your application, or for some longer period of time?

              Judging by your code fragment, I think you want to store the contents in-memory. Question is: why? The file is probably not going anywhere in the meantime, so why do want to keep all its (large) contents into memory? If you really need to, I guess QByteArray is the most efficient class to do it with. At least it won't use UTF-16 if the original file was ASCII or UTF-8 or some other 8-bit encoding. That should save you memory.

              Another side note is: you already have the file in memory, because you are reading from a resource. Why do you insist in keeping another copy of the same file in memory too?[/quote]

              I want to keep all its (large) contents into memory because i want to search a specific data present in the file or not. Is their any other way of doing this without storing all the contents into the memory.

              Pratik Agrawal

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fluca1978
                wrote on last edited by
                #7

                [quote author="Andre" date="1323250299"]Question is: why? The file is probably not going anywhere in the meantime, so why do want to keep all its (large) contents into memory? [/quote]

                Agree!
                I suspect you are going to scan/analyze the file content, and I guess it can be done iterating thru the content of the file instead of loading all the file into memory. With a few more details we could help you in achieving your aim.

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

                  [quote author="pratik041" date="1323251213"]
                  I want to keep all its (large) contents into memory because i want to search a specific data present in the file or not. Is their any other way of doing this without storing all the contents into the memory.[/quote]
                  Sure there is!
                  You can just scan through the file bit by bit. That will be quite fast, as the file is actually in memory already (it is a resource, after all).

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pratik041
                    wrote on last edited by
                    #9

                    So is reading line by line and stopping where i find the required data would be a better idea?

                    Pratik Agrawal

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fluca1978
                      wrote on last edited by
                      #10

                      [quote author="pratik041" date="1323251808"]So is reading line by line and stopping where i find the required data would be a better idea? [/quote]

                      If your aim is just to "grep" the file, yes. In the case the file is 2000 lines long and the word or data you are searching is in the first 10 lines you will avoid scanning all the other 1990 remaining lines. In the worst case, you data is at the end of the file and you will have to scan the whole.
                      By the way, the file is a resource, so aren't you already sure about its content?

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pratik041
                        wrote on last edited by
                        #11

                        my file is something like this

                        @
                        .......................................
                        .......................................
                        .......................................
                        IDDLG_LOGIN OFI_DIALOGEX
                        BEGIN
                        ...........................
                        ........................
                        END
                        ...........................
                        .............................
                        .
                        IDDLG_CONFIRM_OFI_DIALOGEX
                        BEGIN
                        ...........................
                        ...............................
                        END
                        .
                        .
                        @
                        Here suppose i have to find the text "IDDLG_LOGIN OFI_DIALOGEX" .
                        After that i have to do some string operation starting "BEGIN" to "END".
                        .

                        Pratik Agrawal

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

                          Yes.
                          Should be simple enough if you use a line-by-line parsing of your file. Did you try to create an implementation for that yet? Running into any specific issues?

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            pratik041
                            wrote on last edited by
                            #13

                            [quote author="Andre" date="1323256622"]Yes.
                            Should be simple enough if you use a line-by-line parsing of your file. Did you try to create an implementation for that yet? Running into any specific issues?[/quote]

                            Ya i have checked reading line by line to find some specific data it is working fine further i am trying some other operation on the data which i need.

                            Pratik Agrawal

                            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