Fedora Linux Support Community & Resources Center
  #1  
Old 25th July 2012, 06:22 AM
grimx Offline
Registered User
 
Join Date: Apr 2008
Posts: 73
linuxfirefox
[SOLVED] PyQt QThread problem

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
__________________
Fedora 17, 3.3.4-5.fc17.i686.PAE
AMD Sempron(tm) Processor LE-1300
2 GIGS RAM, 320 GIG Hard Drive
NVIDIA GeForce 6160 SE integrated graphics

Last edited by grimx; 25th July 2012 at 06:19 AM.
Reply With Quote
Reply

Tags
problem, pyqt, qthread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Building PyQt in Fedora parsah Programming & Packaging 2 11th December 2010 12:28 AM
problem in Eric the python IDE after updating to PyQt 4.6.2e lio_013 Using Fedora 1 29th December 2009 08:17 PM
PyQt help needed monjuri Using Fedora 2 2nd April 2009 04:38 AM
wxPython, pyGTK or pyQT The_Jaymz Programming & Packaging 7 16th May 2007 01:58 PM


Current GMT-time: 23:32 (Wednesday, 22-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat