Re: [PyQt] timers from mainwindow
Of course thats it, thanks :) On 09/14/2010 08:01 PM, Doug Bell wrote: Sebastian Elsner wrote: I would like to start a QTimer from a mainwindow's menu, creating a new instance of a custom class. See the example below. All works except the timer's callback is never called. Asking if the timer is active returns True. I ran out of ideas. Maybe I misunderstand how timers work?! Any help appreciated. def doit(self): Timers() You're not keeping a reference to your Timers instance. It's getting garbage collected before the timer fires. Doug ___ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] timers from mainwindow
Sebastian Elsner wrote: > I would like to start a QTimer from a mainwindow's menu, creating a > new instance of a custom class. See the example below. All works > except the timer's callback is never called. Asking if the timer is > active returns True. I ran out of ideas. Maybe I misunderstand how > timers work?! Any help appreciated. > > def doit(self): > Timers() You're not keeping a reference to your Timers instance. It's getting garbage collected before the timer fires. Doug ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] timers from mainwindow
Hello, I would like to start a QTimer from a mainwindow's menu, creating a new instance of a custom class. See the example below. All works except the timer's callback is never called. Asking if the timer is active returns True. I ran out of ideas. Maybe I misunderstand how timers work?! Any help appreciated. from PyQt4 import QtCore, QtGui from PyQt4 import uic import sys class Timers(QtCore.QObject): def __init__(self, parent=None): QtCore.QObject.__init__(self) print "Timers instance created" self.timer = QtCore.QTimer() self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.callback) self.timer.start(1000) print self.timer.isActive() def callback(self): print "timer called" class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.menubar = QtGui.QMenuBar(self) self.menuMenu = QtGui.QMenu(self.menubar) self.setMenuBar(self.menubar) self.actionDOIT = QtGui.QAction(self) self.menuMenu.addAction(self.actionDOIT) self.menubar.addAction(self.menuMenu.menuAction()) self.menuMenu.setTitle("menu") self.actionDOIT.setText("DO IT") self.connect(self.actionDOIT, QtCore.SIGNAL("triggered()"), self.doit) def doit(self): Timers() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sys.exit(app.exec_()) Thank you Sebastian ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt