Good day all, I'm currently working on a GUI that will update every 15 seconds. I quite new to Python also, so I'm looking for some guidance I can get here.
I'm getting my data from a .txt file that will update every 15 seconds, so now I tried to feed those data into the GUI every 15 seconds. It works but after a few runs an error code came out at my prompt,
QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)
The GUI will still update every 15 seconds but that error makes me feel like I'm doing wrong already. I wonder is it because I keep on creating new timer in my Cuff loop?
Here's the coding for my GUI.
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import sys
import time
class dataProcessing(QtWidgets.QMainWindow):
def __init__(self):
super(dataProcessing,self).__init__()
uic.loadUi('CuffingEfficiency2.ui',self)
self.show()
self.Cuff()
def Cuff(self):
with open('Cuffing.txt', 'r') as r:
l1,l2,l3,l4,l5,l6 = [float(i) for i in r.readlines()]
self.label_8.setText(str(l1))
self.label_9.setText(str(l3))
self.label_12.setText(str(l5))
self.label_13.setText(str(l2))
self.label_10.setText(str(l4))
self.label_11.setText(str(l6))
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.Cuff)
self.timer.start(15000)
app = QtWidgets.QApplication(sys.argv)
window = dataProcessing()
app.exec_()
Thanks!
Probably the warning is caused because you are creating a new QTimer in each execution of "Cuff", in your case a single QTimer is enough:
class dataProcessing(QtWidgets.QMainWindow):
def __init__(self):
super(dataProcessing, self).__init__()
uic.loadUi("CuffingEfficiency2.ui", self)
self.show()
timer = QtCore.QTimer(self, timeout=self.Cuff, interval=15 * 1000)
timer.start()
self.Cuff()
def Cuff(self):
labels = (
self.label_8,
self.label_9,
self.label_12,
self.label_13,
self.label_10,
self.label_11,
)
with open("Cuffing.txt", "r") as r:
for label, line in zip(
labels,
r.readlines(),
):
try:
label.setNum(float(line))
except ValueError:
pass