[PyQt] Subclassing QNetworkReply
Detlev Offenbach
detlev at die-offenbachs.de
Mon Mar 2 17:33:01 GMT 2009
On Montag, 2. März 2009, Phil Thompson wrote:
> On Mon, 2 Mar 2009 18:19:57 +0100, Detlev Offenbach
>
> <detlev at die-offenbachs.de> wrote:
> > 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
> > --------------
>
> The Python signature is slightly different as Python strings aren't
> mutable. There is no buffer argument and you should return the data as a
> Python string.
>
> Phil
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
So I have to "return l, buffer" with buffer being a Python string. Will this
work even if the method is called from some C++ code of the Qt4 libraries
(e.g. QWebView or QWebPage)?
Detlev
--
Detlev Offenbach
detlev at die-offenbachs.de
More information about the PyQt
mailing list