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. qfile seek

qfile seek

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 4.7k 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.
  • J Offline
    J Offline
    Jeronimo
    wrote on last edited by Jeronimo
    #1

    Hi i have one document in word. And i want this document to separate in two documents with the text i wrote. I was trying to do a seek but was unsuccesfully. Some way to solve this?
    I tried to do this:
    file1.seek(servidor.size() - sizeotherfile );
    newfile.write(servidor.read(sizeotherfile));

    raven-worxR 1 Reply Last reply
    0
    • J Jeronimo

      Hi i have one document in word. And i want this document to separate in two documents with the text i wrote. I was trying to do a seek but was unsuccesfully. Some way to solve this?
      I tried to do this:
      file1.seek(servidor.size() - sizeotherfile );
      newfile.write(servidor.read(sizeotherfile));

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Jeronimo
      such an approach would max. work in a plain text file.
      But you are just literally splitting the file and writing something in between. Most files have a defined structure of course.
      docx for example is based on XML.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      J 1 Reply Last reply
      3
      • raven-worxR raven-worx

        @Jeronimo
        such an approach would max. work in a plain text file.
        But you are just literally splitting the file and writing something in between. Most files have a defined structure of course.
        docx for example is based on XML.

        J Offline
        J Offline
        Jeronimo
        wrote on last edited by
        #3

        @raven-worx i could seek files like txt or doc i did one program for linux but in windows not seems to work

        raven-worxR 1 Reply Last reply
        0
        • J Jeronimo

          @raven-worx i could seek files like txt or doc i did one program for linux but in windows not seems to work

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Jeronimo said in qfile seek:

          but in windows not seems to work

          what exactly doesn't work?!

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          J 1 Reply Last reply
          3
          • raven-worxR raven-worx

            @Jeronimo said in qfile seek:

            but in windows not seems to work

            what exactly doesn't work?!

            J Offline
            J Offline
            Jeronimo
            wrote on last edited by
            #5

            @raven-worx in linux i do this:
            archivo->seek(tamano1.toInt());
            newfile->write(archivo->read(tamano2.toInt()));

            and works extract me the files(for example one .txt in two txt) but when i do for windows like you see upside i can't

            raven-worxR 1 Reply Last reply
            0
            • J Jeronimo

              @raven-worx in linux i do this:
              archivo->seek(tamano1.toInt());
              newfile->write(archivo->read(tamano2.toInt()));

              and works extract me the files(for example one .txt in two txt) but when i do for windows like you see upside i can't

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Jeronimo
              it's impossible to give you any help, when you keep saying that "you can't" or something "doesn't work" and with 2 lines of code.

              What exactly makes you think that it doesn't work?
              What is the output? Is the file completely overwritten (from the beginning)?
              Print the values passed to seek() and read() and make sure they are correct.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              J 1 Reply Last reply
              2
              • raven-worxR raven-worx

                @Jeronimo
                it's impossible to give you any help, when you keep saying that "you can't" or something "doesn't work" and with 2 lines of code.

                What exactly makes you think that it doesn't work?
                What is the output? Is the file completely overwritten (from the beginning)?
                Print the values passed to seek() and read() and make sure they are correct.

                J Offline
                J Offline
                Jeronimo
                wrote on last edited by Jeronimo
                #7

                @raven-worx But my question is i can seek files in other path?????. Works but when i try in other path i can't to seek files in other place i put a little of code to take one idea.

                Motherfile->seek(Motherfile->size() - 1024);
                i read the mother file
                trama = Motherfile->read(1024);
                after i use one split to separate the different sizes of files with names
                tamano1 = trama.split("|@|")[0];
                tamano2 = trama.split("|@|")[1];
                tamano3 = trama.split("|@|")[2];
                nombre1 = trama.split("|@|")[3];
                nombre2 = trama.split("|@|")[4];

                And then i select path of my files
                First-txt->setFileName("./" + nombre1);
                Second-txt->setFileName("./" + nombre2);

                First-txt-->open(QFile::WriteOnly);
                Second-txt->open(QFile::WriteOnly);
                Motherfile->seek(tamano1.toInt());
                First-txt-->write(archivoStub->read(tamano2.toInt()));
                Motherfile->seek(tamano1.toInt() + tamano2.toInt());
                Second-txt->write(archivoStub->read(tamano3.toInt()));
                First-txt-->close();
                Second-txt->close();

                But when i try to put in other path for example in my Home i can't why i can't change the path?? or i am unclear still?

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

                  Hi
                  Change path how?
                  Do you mean with
                  void QFile::setFileName(const QString &name)
                  "Sets the name of the file. The name can have no path, a relative path, or an absolute path."
                  Do not call this function if the file has already been opened.

                  J 1 Reply Last reply
                  3
                  • mrjjM mrjj

                    Hi
                    Change path how?
                    Do you mean with
                    void QFile::setFileName(const QString &name)
                    "Sets the name of the file. The name can have no path, a relative path, or an absolute path."
                    Do not call this function if the file has already been opened.

                    J Offline
                    J Offline
                    Jeronimo
                    wrote on last edited by Jeronimo
                    #9

                    @mrjj Solved i changed putting the path in setfilename but one questionwhy when i open show me different files if i have one only txt???

                    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