I'm trying to update the QLabel in test.py using TimeThread from TimeThread.py.
I get this error....
Code:
Traceback (most recent call last):
File "/home/..../workspace/Python/Test/test.py", line 37, in <module>
t = Test()
File "/home/..../workspace/Python/Test/test.py", line 18, in __init__
self.myTimeThread.start()
RuntimeError: underlying C/C++ object has been deleted
when i run test.py
Code:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from TimeThread import TimeThread
class Test(QDialog):
def __init__(self, parent=None):
super(Test, self).__init__(parent)
self.theTime = QDateTime.currentDateTime()
self.lbl = QLabel(self.theTime.toString("ddd MMM yyyy hh:mm:ss ap"))
self.lbl.setAlignment(Qt.AlignHCenter)
self.myTimeThread = TimeThread(self.lbl)
self.myTimeThread.start()
self.setToolTip("The Test Dialog")
self.btn = QPushButton("Close")
self.connect(self.btn, SIGNAL("clicked()"),
self, SLOT("close()"))
vbox = QVBoxLayout()
vbox.addWidget(self.lbl)
vbox.addWidget(self.btn)
self.setLayout(vbox)
self.setWindowTitle("Test")
app = QApplication(sys.argv)
t = Test()
t.show()
app.exec_()
Here is TimeThread.py
Code:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class TimeThread(QThread):
def __init__(self, lbl):
self.label = lbl
self.timer = QTimer()
self.connect(self.timer, SIGNAL("timeout()"), self.getTime)
def run(self):
self.timer.start(1000)
def getTime(self):
theTime = QDateTime.currentDateTime()
self.label.setText(theTime.toString("ddd MMM yyyy hh:mm:ss ap"))
---------- Post added at 10:22 PM ---------- Previous post was at 09:13 PM ----------
Code:
in class TimeThread(QThread):
def __init__(self, lbl):
super(TimeThread, self).__init__() <<<====== I forgot