[PyQt] newbie question about slots and signals

Robin Wittler real at the-real.org
Thu Jun 17 18:21:41 BST 2010


Hi,

i am totaly new to pyqt4 and it seems that i have a problem to 
understand how signals and slots working.
First i thought this is all clear to me, but then i wrote this little 
code snippet and - surprise surprise - it didn't work.
The moep method where never called. I've tried it with the 
QtCore.pyqtSlot dekorator, but this didn't work neither.
So what am i doing wrong? What have i missunderstud?

cheers,
robin



#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtWebKit
from PyQt4 import QtSvg
from PyQt4 import QtNetwork

class Browser(QtWebKit.QWebView):
     def __init__(self, **kargs):
         QtWebKit.QWebView.__init__(self)
         self.manager = QtNetwork.QNetworkAccessManager()
         self.proxy = self.manager.proxy()
         self.proxy.setHostName('127.0.0.1')
         self.proxy.setPort(8080)
         self.proxy.setType(self.proxy.HttpProxy)
         self.manager.setProxy(self.proxy)
         self._page = self.page()
         self._page.setNetworkAccessManager(self.manager)
         self.connect(
                 self._page,
                 QtCore.SIGNAL('loadFinished(bool)'),
                 self.moep
         )

     def run(self):
         self._page.mainFrame().load(QtCore.QUrl('http://google.de'))

     def moep(self):
         print "load finished"


if __name__ == '__main__':
     app = QtGui.QApplication([])
     b = Browser()
     b.showFullScreen()
     b.run()
     sys.exit(app.exec_())


More information about the PyQt mailing list