Ok, I'm still not getting this working.
I have written a bare-bones app to illustrate what I want to do:
This is my main file: (test2_ui.py)
from test2 import *
from PyQt4 import QtCore, QtGui
def __init__(self, parent=None):
QtGui.
QWidget.__init__
(self, parent
) self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.
QObject.
connect(self.
ui.
pushButton,QtCore.
SIGNAL("clicked()"), self.
ok)
def closeApp(self):
self.close()
def ok(self):
import testlib
tl = testlib.lazyworker()
QtCore.
QObject.
connect(tl,QtCore.
SIGNAL("update(int)"), self.
updateUI) tl.doWork()
def updateUI(self, prog):
self.ui.label.setText(str(prog))
if __name__ == "__main__":
import sys
panel = StartQT4()
panel.show()
sys.exit(app.exec_())
from test2 import *
from PyQt4 import QtCore, QtGui
class StartQT4(QtGui.QMainWindow,):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"), self.ok)
def closeApp(self):
self.close()
def ok(self):
import testlib
tl = testlib.lazyworker()
QtCore.QObject.connect(tl,QtCore.SIGNAL("update(int)"), self.updateUI)
tl.doWork()
def updateUI(self, prog):
self.ui.label.setText(str(prog))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
panel = StartQT4()
panel.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
This is my UI include: (test2.py)
from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.
label = QtGui.
QLabel(Dialog
) self.
label.
setGeometry(QtCore.
QRect(70,
120,
221,
16)) self.label.setObjectName("label")
self.
pushButton.
setGeometry(QtCore.
QRect(70,
180,
231,
91)) self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
def retranslateUi(self, Dialog):
from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(70, 120, 221, 16))
self.label.setObjectName("label")
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(70, 180, 231, 91))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Dialog", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
To copy to clipboard, switch view to plain text mode
This is my module with class inside: (testlib.py)
import time
from PyQt4 import QtCore, QtGui
class lazyworker:
def doWork(self):
for self.i in range(0,100):
time.sleep(0.1)
self.emit(SIGNAL("update(int)"), self.i)
import time
from PyQt4 import QtCore, QtGui
class lazyworker:
def doWork(self):
for self.i in range(0,100):
time.sleep(0.1)
self.emit(SIGNAL("update(int)"), self.i)
To copy to clipboard, switch view to plain text mode
When I try to run this I get the following error:
TypeError: arguments did not match any overloaded call:
QObject.
connect(QObject,
SIGNAL(),
QObject,
SLOT(), Qt.
ConnectionType=Qt.
AutoConnection): argument
1 has unexpected type
'lazyworker' QObject.
connect(QObject,
SIGNAL(), callable, Qt.
ConnectionType=Qt.
AutoConnection): argument
1 has unexpected type
'lazyworker' QObject.
connect(QObject,
SIGNAL(),
SLOT(), Qt.
ConnectionType=Qt.
AutoConnection): first argument of unbound method must have type
'QObject'
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'lazyworker'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'lazyworker'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): first argument of unbound method must have type 'QObject'
To copy to clipboard, switch view to plain text mode
I gather this is because it wants a class of type Qobject, not my "lazyworker" type.
I'm not really sure what do to from here.
Thanks in advance!
R
Bookmarks