Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    13
    3741
    Loading More Posts
    • 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
      pratik041 last edited by

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

      Pratik Agrawal

      1 Reply Last reply Reply Quote 0
      • R
        Rahul Das last edited by

        QByteArray , i suppose.


          Rahul Das
        

        1 Reply Last reply Reply Quote 0
        • ?
          Guest last edited by

          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 Reply Quote 0
          • R
            Rahul Das last edited by

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


              Rahul Das
            

            1 Reply Last reply Reply Quote 0
            • A
              andre last edited by

              "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 Reply Quote 0
              • P
                pratik041 last edited by

                [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 Reply Quote 0
                • F
                  fluca1978 last edited by

                  [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 Reply Quote 0
                  • A
                    andre last edited by

                    [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 Reply Quote 0
                    • P
                      pratik041 last edited by

                      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 Reply Quote 0
                      • F
                        fluca1978 last edited by

                        [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 Reply Quote 0
                        • P
                          pratik041 last edited by

                          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 Reply Quote 0
                          • A
                            andre last edited by

                            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 Reply Quote 0
                            • P
                              pratik041 last edited by

                              [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 Reply Quote 0
                              • First post
                                Last post