[PyQt] QWebHistory load/save

Phil Thompson phil at riverbankcomputing.com
Mon Mar 15 18:48:40 GMT 2010


On Mon, 15 Mar 2010 13:24:21 -0500, Russell Valentine
<russ at coldstonelabs.org> wrote:
> Yes, my fault. How about this one:
> It will be a while before I can try it. In the process up upgrading to
> Qt4.6
> ===========
> 
> from PyQt4 import QtCore, QtGui, QtWebKit
> import sys
> 
> 
> class MainWindow(QtGui.QMainWindow):
>      def __init__(self):
>          super(QtGui.QMainWindow, self).__init__()
>          self.webview=QtWebKit.QWebView()
>          self.setCentralWidget(self.webview)
>      def go(self):
>          self.webview.load(QtCore.QUrl("http://python.org"))
>          f=QtCore.QFile("history.file")

           f.open(QtCore.QIODevice.WriteOnly)

>          d=QtCore.QDataStream(f)
>          d << (self.webview.history())
> 
> 
> 
> if __name__ == "__main__":
>      app = QtGui.QApplication(sys.argv)
>      window = MainWindow()
>      window.show()
>      QtCore.QTimer.singleShot(1000, window.go)
>      sys.exit(app.exec_())

With this I get a 12 byte file - not an empty file.

The history isn't updated until the load is finished. If you connect the
loadFinished() signal to a slot that writes the history I get a 254 byte
file.

Phil


More information about the PyQt mailing list