【发布时间】:2014-08-20 17:21:03
【问题描述】:
我必须将一个函数中发生的异常传递给另一个类中的插槽。
_qObject = QtCore.QObject()
except Exception, ex:
QtCore.QObject.emit(_qObject, QtCore.SIGNAL("error_occured"))
我想将 ex 传递给具有
的类QtCore.QObject.connect(_qObject, QtCore.SIGNAL("error_occured"), self.__errorOccured)
这是我的情况
from PyQt4.QtCore import pyqtSignal, pyqtSlot
from PyQt4.QtGui import QWidget, QApplication
has_error = pyqtSignal(Exception)
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
has_error.connect(self.thrown_error)
@pyqtSlot(Exception)
def thrown_error(self, my_err):
#Do Stuff with the Exception
print(type(my_err), my_err)
self.close()
def makeError():
try:
print 1/0
except ZeroDivisionError, ze:
has_error.emit(ze)
app = QApplication([])
SomeOtherClass()
【问题讨论】:
标签: qt pyqt pyside signals-slots