Results 1 to 7 of 7

Thread: Subclassing QNetworkReply

Hybrid View

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

    Default Re: Subclassing QNetworkReply

    Use the decorator or proxy pattern.
    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.


  2. #2
    Join Date
    May 2009
    Posts
    133
    Thanks
    10
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassing QNetworkReply

    This was the answer that answers my question

    What would you say to add Visitor to the mix like this

    Qt Code:
    1. struct ExtendedNetworkReply : public QNetworkReply
    2. {
    3. virtual void doStuff() = 0;
    4. // the rest
    5. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. struct SynchNetworkReply : public ExtendedNetworkReply
    2. {
    3. virtual void doStuff() {};
    4. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. struct AsynchNetworkReply : public ExtendedNetworkReply
    2. {
    3. virtual void doStuff() {};
    4. };
    To copy to clipboard, switch view to plain text mode 
    and use doStuff() instead of checking tag? I guess it's more OO style

    And two more questions;

    1. One can avoid all this subclassing using one dynamic property of QNetworkReply (QObject in fact) to tag replies. Which one you think is better and why?

    2. If QNetworkReply is meant to be extended by inheritance and used polimorphically why doesn't it have virtual destructor?
    Last edited by piotr.dobrogost; 8th September 2009 at 10:28.

  3. #3
    Join Date
    May 2009
    Posts
    133
    Thanks
    10
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassing QNetworkReply

    Quote Originally Posted by wysota View Post
    Use the decorator or proxy pattern.
    I've found the example of proxy for QNetworkReply here.

    I don't quite understand what's the reason for calling base subobject's methods in the following places:

    Qt Code:
    1. NetworkReplyProxy::NetworkReplyProxy(QObject* parent, QNetworkReply* reply) {
    2. ...
    3. setOperation(m_reply->operation());
    4. setRequest(m_reply->request());
    5. setUrl(m_reply->url());
    6. ...
    7. }
    8.  
    9.  
    10. // QIODevice proxy...
    11. virtual qint64 bytesAvailable() const {
    12. return m_buffer.size() + QIODevice::bytesAvailable(); // <-- QIODevice::bytesAvailable() ?
    13. }
    14.  
    15. // not possible...
    16. void setReadBufferSize(qint64 size) {
    17. QNetworkReply::setReadBufferSize(size); // <-- ???
    18. m_reply->setReadBufferSize(size);
    19. }
    20.  
    21. void errorInternal(QNetworkReply::NetworkError _error)
    22. {
    23. setError(_error, errorString()); // <-- ???
    24. emit error(_error);
    25. }
    To copy to clipboard, switch view to plain text mode 
    Shouldn't proxy forward all calls to the original object?
    Last edited by piotr.dobrogost; 18th December 2010 at 20:33.

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

    Default Re: Subclassing QNetworkReply

    In the first case bytesAvailable() of QIODevice is called because the latter has its own internal buffer that can contain some of the data. There is a labs article about it somewhere.
    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. Finding filename from QNetworkReply
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2009, 09:29
  2. Custom QNetworkReply for WebView
    By victor.yacovlev in forum Qt Programming
    Replies: 0
    Last Post: 1st April 2009, 13:32
  3. When to delete QNetworkReply?
    By QPlace in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2009, 12:46
  4. Replies: 2
    Last Post: 14th February 2008, 20:06
  5. Subclassing QScrollView
    By sumsin in forum Qt Programming
    Replies: 13
    Last Post: 16th March 2006, 14:20

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