[PyQt] newbie question about slots and signals

Darryl Wallace darryl.wallace at prosensus.ca
Thu Jun 17 18:52:58 BST 2010


Hello

-----Original Message-----
From: pyqt-bounces at riverbankcomputing.com
[mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Robin Wittler
Sent: June-17-10 1:22 PM
To: pyqt at riverbankcomputing.com
Subject: [PyQt] newbie question about slots and signals

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_())


----------------------
The signal/slot connection seems to be working properly for me as "load
finished" appears in my console.  The webpage, however, didn't load.

Though, I would recommend a simpler example to learn the use of signals
and slots.  Why not just make a widget with a QPushButton and connect the
button's "clicked()" signal to a slot.

Darryl


More information about the PyQt mailing list