Results 1 to 5 of 5

Thread: QFile, QTextStream, seek()

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QFile, QTextStream, seek()

    Hello all,
    sorry if I'm making a silly mistake here, but I'm not sure what the best way is.
    I'm making a file that has several blocks (at predefined positions). When I create the file, the blocks are not full (i.e. not contiguous). They will be filled later. So, I'd like to skip/extend the file to the position of the next block. Using a seek() and a write just appends and doesn't work.

    how do I extend file?
    thanks
    K
    below is the code:

    Qt Code:
    1. //make a new file with name in the directory
    2. file = new QFile(path +"\\"+ name);
    3. if(file->open(QIODevice::Append))
    4. fileName = name;// the file has been opened
    5. else
    6. return -1;
    7.  
    8. // make a text stream
    9. QTextStream stream( file );
    10.  
    11. // write the header
    12. stream.seek(POS_HEADER);
    13. stream << makeHeader();
    14.  
    15. // write the comments block
    16. QString comments("This is the standard comments block");
    17. stream.seek( POS_HEADER_COMMENT);
    18. stream << comments;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile, QTextStream, seek()

    Quote Originally Posted by TheKedge View Post
    open(QIODevice::Append)
    Maybe you should use QIODevice::ReadWrite to make seek() work?

  3. The following user says thank you to jacek for this useful post:

    TheKedge (29th September 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QFile, QTextStream, seek()

    I know why you've had more thanks than posts.
    thanks
    K

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile, QTextStream, seek()

    Quote Originally Posted by TheKedge View Post
    I know why you've had more thanks than posts.
    Are you sure he has more thanks than posts?

    It is true that his thank ratio per thanked post is greater than 1.00 though

  6. The following user says thank you to wysota for this useful post:

    TheKedge (29th September 2006)

  7. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QFile, QTextStream, seek()

    Ahh, I see,

    so he has 359 thanks in 2504 posts ... that's only ...erm, 14% useful posts

    K

Similar Threads

  1. Reading File using QFile and QTextStream
    By atm in forum Qt Programming
    Replies: 4
    Last Post: 13th July 2006, 23:12
  2. Qfile and QTextStream
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2006, 10:43
  3. QTextStream capture stdout from xsltParseStylesheetFile
    By patrik08 in forum Qt Programming
    Replies: 9
    Last Post: 25th June 2006, 11:24
  4. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 07:26
  5. qtextstream & qstring
    By mickey in forum Newbie
    Replies: 3
    Last Post: 24th February 2006, 19:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.