Hello,
I am trying to create a windows desktop program gui with Pyqt6 and
Pyinstaller. I got a simple hello world program that has uses a signal and
threading to send updated time from localtime function.
Anyway, I get a runtime error from this line of code:
"engine.rootObjects()[0].setProperty('backend', backend)"
The error reads:
"Unhandled exception in script.
Failed to execute script 'main' due to unhandled exception: list index out
of range
Traceback (most recent call last):
File "main.py", line 52, in <module>
IndexError: list index out of range"
I think it's because the rootObject list is dynamic, and doesn't have any
list items until runtime. However, I don't know how to rectify a runtime
error like this.
Code is bellow, and I added a few debugging lines since I built the
program. So, that is why if you count, line 52 is no longer correct for the
line of code in question. Any help would be greatly appreciated, thank you!
"
#############################################
# main.py for PyQt6 Hello World #
# #
#############################################
import sys
import os
import threading
#gmtime is 6 hours later than here, depending on dst
+/- 1 hr
from time import strftime, sleep, localtime
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine
from PyQt6.QtQuick import QQuickWindow
from PyQt6.QtCore import QObject, pyqtSignal
#currentTime = strftime("%H:%M:%S", gmtime())
class Backend(QObject):
def __init__(self):
QObject.__init__(self)
updated = pyqtSignal(str, arguments=['updater'])
def updater(self, currentTime):
self.updated.emit(currentTime)
def bootUp(self):
t_thread = threading.Thread(target=self._bootUp)
t_thread.daemon = True
t_thread.start()
def _bootUp(self):
while True:
currentTime = strftime("%H:%M:%S", localtime())
print(currentTime)
self.updater(currentTime)
sleep(1) #use 0.1
QQuickWindow.setSceneGraphBackend('software')
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
engine.load('./UI/main.qml')
backend = Backend()
rootObjects = engine.rootObjects()
print("rootObjects type: ", type(rootObjects), "\n")
print("rootObjects len: ", len(rootObjects), "\n")
print("rootObjects: ", rootObjects, "\n")
#engine.rootObjects()[0].setProperty('backend', backend)
rootObjects[0].setProperty('backend', backend)
#engine.rootObjects()[0].setProperty('currentTime', currentTime)
backend.bootUp()
sys.exit(app.exec())
"
--
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyinstaller/d99cef17-9ba8-4620-a527-9de74cc736bfn%40googlegroups.com.