2

I have this script with which I would like to do some more stuff when it is ready:

from PyQt4 import QtCore, QtGui, QtWebKit

class WebViewCreator:
    def __init__(self):

        self.view = QtWebKit.QWebView()
        self.view.setPage(QtWebKit.QWebPage())

        self.view.connect(self.view, QtCore.SIGNAL('loadFinished(bool)'), self.load_finished)

        path = self.app.resources_uri() + "/index.html"
        self.view.load(QtCore.QUrl(path))

    def load_finished(self, ok):
        print ok

def onDone(ok):
    print ok

The problem I have is that if I connect a function to the loadFinished(bool) signal then the function gets executed, but if I connect a method of the object like self.load_finished then this method is not called and I can't understand why :-/

The same happens with:

self.view.loadFinished.connect(onDone)

versus:

self.view.loadFinished.connect(self.load_finished)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Jeena
  • 2,172
  • 3
  • 27
  • 46

1 Answers1

4

There's nothing obviously wrong with the code you posted.

Which is to say, when I run this slightly simplified version of it, it loads the page successfully and (eventually) prints True:

from PyQt4 import QtCore, QtGui, QtWebKit

class WebViewCreator(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.view = QtWebKit.QWebView(self)
        self.view.loadFinished.connect(self.load_finished)
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.view)
        self.view.load(QtCore.QUrl('http://stackoverflow.com/'))

    def load_finished(self, ok):
        print ok

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = WebViewCreator()
    window.show()
    sys.exit(app.exec_())

This is using Python 2.7.3, Qt 4.8.3, and PyQt 4.9.5 on Linux.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Thank you very much, I was fiddeling with it the whole evening, I will make the same changes and go on to the next task even though I don't understand what it was I was doing wrong, yet ;) – Jeena Nov 16 '12 at 00:50