Skip to content

Instantly share code, notes, and snippets.

@sanfx
Created July 4, 2014 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanfx/4500653eafa3381cf233 to your computer and use it in GitHub Desktop.
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.
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