Results 1 to 7 of 7

Thread: How to write contents of a QTcpSocket to a binary file?

  1. #1
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Question How to write contents of a QTcpSocket to a binary file?

    Hi all

    i wrote a program that by HTTP protocol , connect to a download host and download a specific file.
    for connection i used a QTcpSocket that connect to port 80 and send HTTP request,
    when receive data from host, i don't know how to saves content of file not whole of received data to a binary file
    please help me!

    Regards.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to write contents of a QTcpSocket to a binary file?

    If I understand correctly, you want to know how to extract the contents of the file from the HTTP reply. This amounts to reimplementing (at least a part of) the HTTP protocol on top of QTcpSocket. Why don't you use the implementation (QNetworkAccessManager and related classes) already provided by Qt?

  3. #3
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to write contents of a QTcpSocket to a binary file?

    bkz i love QTcpSocket
    lol

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to write contents of a QTcpSocket to a binary file?

    With all due respect, this seems to me like a very wrong reason for reinventing the wheel. You would save yourself hundreds of lines of code and tens of hours of coding/debugging/maintenance by using an existing implementation, especially when it is well documented like Qt's. Anyway your question is not directly related to Qt, but to the HTTP.

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

    Default Re: How to write contents of a QTcpSocket to a binary file?

    Quote Originally Posted by Ali Reza View Post
    i don't know how to saves content of file not whole of received data to a binary file
    1. open file
    2. if needed, preprocess the downloaded data according to the protocol your are using
    3. write content of the downloaded data to the file
    4. close file

    To do #2, you need to:
    1. learn about HTTP
    2. learn about Base64 and GZIP/DEFLATE
    3. learn about MIME

    ...or just change your affections and use QNetworkAccessManager.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to write contents of a QTcpSocket to a binary file?

    @ wysota
    hello sir
    please explain a little about "Base64 and GZIP/DEFLATE"

    thanks in advance.

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

    Default Re: How to write contents of a QTcpSocket to a binary file?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to write and read from binary files
    By Momergil in forum Newbie
    Replies: 9
    Last Post: 28th November 2011, 11:58
  2. Replies: 1
    Last Post: 30th September 2011, 15:49
  3. Using QTcpSocket to receive binary data
    By felo188 in forum Qt Programming
    Replies: 5
    Last Post: 23rd August 2011, 15:03
  4. Replies: 2
    Last Post: 2nd November 2010, 05:15
  5. How to write a QList into a binary file?
    By Lawand in forum Qt Programming
    Replies: 23
    Last Post: 15th June 2009, 10:04

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.