Plugin that starts a QThread - QTimer not working

MakeHuman python API, python plugins, etc

Moderator: joepal

Plugin that starts a QThread - QTimer not working

Postby yomomano » Tue Jan 12, 2016 2:31 pm

Below my attempt to make a plugin that starts a thread at start-up and should call 'checkIt' every 1000ms.
The thread is created, but QTimer seems to do nothing ('checkIt' is never called).

What am I doing wrong?

Code: Select all
from PyQt4 import QtCore

class JobThread(QtCore.QThread):
    def __init__(self, app):
        QtCore.QThread.__init__(self)
        self.app = app
        self.app.logger_async.warning('INIT')

    def __del__(self):
        self.wait()

    def run(self):
        self.app.logger_async.warning('RUN')
        # call checkIt every 1000ms
        self.job_timer = QtCore.QTimer()
        self.job_timer.singleShot(False)
        self.job_timer.start(1000)
        self.job_timer.timeout.connect(self.checkIt)
        self.app.logger_async.warning('TIMER STARTED')

    def checkIt(self):
        # do smth
        self.app.processEvents() # required??
        self.app.logger_async.warning('CHECK')

def load(app):
    jobThread = JobThread(app)
    jobThread.start()

def unload(app):
    pass
yomomano
 
Posts: 1
Joined: Tue Jan 12, 2016 11:16 am

Return to Python scripts

Who is online

Users browsing this forum: No registered users and 1 guest