Results 1 to 3 of 3

Thread: Subclassing QNetworkAccessManager in order to save HTTP resources

  1. #1
    Join Date
    Dec 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Subclassing QNetworkAccessManager in order to save HTTP resources

    Hello guys,
    I'll get straight to the point:
    In my code (PyQt), I'm Trying to subclass QNetworkAccessManager so that I could get the data in QNetworkReply, without affecting the contents of the reply.
    I do this by connecting myself to readyRead, once readyRead is called I peek the size of bytesAvailable and append that to my own attribute containing the data.
    When data is unsupported, it is not read and so the buffer is not cleared, I notice that and change the append to an add.

    Qt Code:
    1. if reply.isReadable() and reply.isOpen() and reply.bytesAvailable():
    2. reply_data = b''
    3.  
    4. bytes_available = reply.bytesAvailable()
    5. while len(reply_data) < bytes_available:
    6. bytes_to_read = bytes_available - len(reply_data)
    7. reply_data += bytes(reply.peek(bytes_to_read))
    8.  
    9. if hasattr(reply, 'is_unsupported') and reply.is_unsupported:
    10. reply.data = reply_data
    11. else:
    12. reply.data += reply_data
    To copy to clipboard, switch view to plain text mode 

    However, this still doesn't cover all of the times where the buffer is not cleared, and so at certain times reply.data will appear to hold duplicated data, since it is appended instead of instantiated.

    Any helpful insights?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Subclassing QNetworkAccessManager in order to save HTTP resources

    What are you trying to achieve from the reply user's point of view? Why can't the reply user achieve this for themselves?

  3. #3
    Join Date
    Dec 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Subclassing QNetworkAccessManager in order to save HTTP resources

    Hey Chris,
    There is no reply user, please explain your question more thoroughly if you can.

    If it helps, I created a similar question on SO
    Similar question

    Perhaps the explanation there is better.

Similar Threads

  1. Http Posting using QNetworkAccessManager
    By Mohammadhzp in forum Newbie
    Replies: 17
    Last Post: 24th January 2014, 18:00
  2. Replies: 1
    Last Post: 19th January 2013, 19:27
  3. QNetworkAccessManager and http redirection
    By grayfox in forum Qt Programming
    Replies: 5
    Last Post: 8th July 2011, 18:24
  4. HTTP Post from QNetworkAccessManager - no data sent
    By secureboot in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2011, 19:46
  5. QNetworkAccessManager Http Basic Authentication?
    By jloundy in forum Qt Programming
    Replies: 5
    Last Post: 29th December 2010, 01:19

Tags for this Thread

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.