My UI (Qt Designer) has a "Start"-button, a "Stop"-button and a lcdNumber, which should display the seconds between clicking "Start" and "Stop". I followed the instructions there: Can't seem to get pyqt countdown timer to work
But my timeout isn't working, although connect was proposed to me while writing that line: QtCore.QTimer.timeout.connect(self.tick_timer) AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'connect'
I also tried to implement lines like that (QtCore.QTimer.connect(QtCore.QTimer(), QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("func()"))) in my update_timer function, but this causes errors (Object::connect: No such slot MainWindow::func()
Object::connect: (receiver name: 'MainWindow')) and I don't really understand how to use the connect signal with timeout.
If I comment this "timeout"-line out, the MainWindow appears, but clicking the "Start"-button obviously runs the "tick_timer" function only once, because the lcd-display shows 0:01.
Thanks for your help!
from PyQt4 import QtCore, QtGui, uic
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
uic.loadUi('MainWindow.ui', self)
# Buttons
self.QStartButton.clicked.connect(self.start_timer)
self.QStopButton.clicked.connect(self.stop_timer)
# Timer
QtCore.QTimer.timeout.connect(self.tick_timer)
def start_timer(self):
self.now = 0
self.tick_timer()
QtCore.QTimer.start
def update_timer(self):
self.runtime = "%d:%02d" % (self.now/60,self.now % 60)
self.lcdNumber.display(self.runtime)
def tick_timer(self):
self.now += 1
self.update_timer()
def stop_timer(self):
QtCore.QTimer.stop