Results 1 to 6 of 6

Thread: problem in writing text with QFile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: problem in writing text with QFile

    1. Seeking in a socket device doesn't make sense as it is not a random access device.
    2. If you use QDataStream, you don't need to send the size of QByteArray as QDataStream will do that for you. Remember that this is a serialization mechanism, not a simple binary stream.
    3. connectToHost() is an asynchronous call - you have to wait for the connection to be established before sending/receiving any data. The same goes for disconnectFromHost (I think you meant that and not disconnect(), right?).

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

    wei243 (6th March 2007)

  3. #2
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    9

    Default Re: problem in writing text with QFile

    thx wysota.

    QTextStream slove my 1st problem in writing text to a file.
    QFile file(filename);
    file.open(QIODevice::WriteOnly);
    QTextStream textstream(&file);
    textstream << text;
    i apply it in writing a picture file with QDataStream.
    but nothing appear in the picture file.
    wat should i do?

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

    Default Re: problem in writing text with QFile

    Quote Originally Posted by wei243 View Post
    i apply it in writing a picture file with QDataStream.
    but nothing appear in the picture file.
    wat should i do?
    You can't use a text stream to handle binary data... I suggest you don't use streams at all with binaries or use QDataStream::readRawData and QDataStream::writeRawData instead of << and >> operators.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  4. Writing Text on a Rectangle!!!
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2006, 10:23
  5. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45

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.