Important: Please read the Qt Code of Conduct -

qfile seek

  • 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: - sizeotherfile );

  • Moderators

    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.

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

  • Moderators

    @Jeronimo said in qfile seek:

    but in windows not seems to work

    what exactly doesn't work?!

  • @raven-worx in linux i do this:

    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

  • Moderators

    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.

  • @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);

    Motherfile->seek(tamano1.toInt() + tamano2.toInt());

    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?

  • Lifetime Qt Champion

    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.

  • @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???

Log in to reply