Created
July 4, 2014 17:31
-
-
Save sanfx/4500653eafa3381cf233 to your computer and use it in GitHub Desktop.
This example shows how to emit signal from a function at module level , signal in turn is connected to SLOT in the class that can perform some action.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt4.QtCore import pyqtSignal, pyqtSlot | |
from PyQt4.QtGui import QWidget, QApplication | |
from PyQt4 import QtCore | |
import sys | |
_qObject = QtCore.QObject() | |
class SomeOtherClass(QWidget): | |
# this is my UI class | |
def __init__(self, parent=None): | |
super(SomeOtherClass, self).__init__(parent) | |
# Initialise the Class and connect signal to slot | |
QtCore.QObject.connect(_qObject, QtCore.SIGNAL("error_occured"), self.thrown_error) | |
def thrown_error(self, my_err): | |
#Do Stuff with the Exception | |
print(type(my_err), my_err) | |
def makeError(): | |
try: | |
print 1/0 | |
except ZeroDivisionError, ex: | |
QtCore.QObject.emit(_qObject, QtCore.SIGNAL("error_occured"), str(ex)) | |
app = QApplication(sys.argv) | |
win = SomeOtherClass() | |
makeError() | |
win.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment