[PyQt] Subclassing QNetworkReply

Detlev Offenbach detlev at die-offenbachs.de
Mon Mar 2 17:19:57 GMT 2009


Hi,

I am trying to write a subclass of QNetworkReply. This subclass needs to have 
it's own variant of the readData protected method. However, it seems, that 
this method doesn't work correctly. How do I have to do this correctly. My 
code is shown below.

--------------
class HelpNetworkReply(QNetworkReply):
    def __init__(self, request, fileData):
        QNetworkReply.__init__(self)
        
        self.__data = QBuffer(fileData)
        
        self.setRequest(request)
        self.setOpenMode(QIODevice.ReadOnly)
        
        self.setHeader(QNetworkRequest.ContentTypeHeader,
		       QVariant("text/html"))
        self.setHeader(QNetworkRequest.ContentLengthHeader, 
                       QVariant(QByteArray.number(fileData.length())))
        QTimer.singleShot(0, self, SIGNAL("metaDataChanged()"))
        QTimer.singleShot(0, self, SIGNAL("readyRead()"))
    
    def abort(self):
        # do nothing
        pass
    
    def readData(self, buffer, maxlen):
        l = self.__data.readData(buffer, maxlen)
        if self.__data.bytesAvailable() == 0:
            QTimer.singleShot(0, self, SIGNAL("finished()"))
        return l
--------------

Regards,
Detlev
-- 
Detlev Offenbach
detlev at die-offenbachs.de


More information about the PyQt mailing list