Results 1 to 8 of 8

Thread: Read/Write from QTextStream

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    4
    Qt products
    Qt4
    Thanks
    1

    Default Re: Read/Write from QTextStream

    Thanks. I missed that seek() function completely. Implementing seek() to the QByteArray case seems to be working.

    example:

    Qt Code:
    1. QString buffer = "funny world";
    2.  
    3. QByteArray array;
    4. array.append(buffer);
    5. QTextStream out(&array,QIODevice::ReadWrite);
    6.  
    7. //out.pos() == 0
    8. out << "hello"; //"hello" overwrites "funny"
    9.  
    10. out.seek(0); // set position to 0
    11.  
    12. QString string;
    13. QString string2;
    14.  
    15. // stream == "hello world"
    16. // QTextStream reads into strings word by word delimited by space
    17. out >> string; // == "hello"
    18. out >> string2; // == "world"
    To copy to clipboard, switch view to plain text mode 
    Last edited by tonde; 31st July 2008 at 11:21.

  2. #2
    Join Date
    Jul 2008
    Posts
    69
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Default Re: Read/Write from QTextStream

    can we use the seek function with a delimiter?

    e.g. |word1|word2|....
    with delimiter "|"

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

    Default Re: Read/Write from QTextStream

    Quote Originally Posted by SunnySan View Post
    can we use the seek function with a delimiter?
    No, you have to use QString::indexOf() or similar method.

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

    SunnySan (31st July 2008)

Similar Threads

  1. QTextStream : Remove a Line?
    By kaydknight in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2011, 19:15
  2. when close QTextStream
    By mattia in forum Newbie
    Replies: 1
    Last Post: 24th November 2007, 14:17
  3. Create QTextStream
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2007, 21:25
  4. reading from QTextStream
    By matyi52 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th December 2006, 08:26
  5. QTextStream capture stdout from xsltParseStylesheetFile
    By patrik08 in forum Qt Programming
    Replies: 9
    Last Post: 25th June 2006, 12:24

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
  •  
Qt is a trademark of The Qt Company.