I am working on a project where I have to make a multi-screen/window application. I am using QML and PySide6 for this purpose. The flow of my applications is like below:
login screen -> search screen (search for certain items) -> test screen (performs some operations) -> reports screen (displays results from test screen).
Currently what I am doing is using a main.py file to load the login page:
import os
from pathlib import Path
import sys
from api_login_test import get_credentials
# from login_data import get_credentials
from PySide6.QtCore import QCoreApplication, Qt, QUrl, QObject
from PySide6.QtWidgets import QApplication, QLineEdit, QPushButton
from PySide6.QtQml import QQmlApplicationEngine
CURRENT_DIRECTORY = Path(__file__).resolve().parent
def main():
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
credentials = get_credentials()
engine.rootContext().setContextProperty('credentials', credentials)
login_file = os.fspath(CURRENT_DIRECTORY / "qml" / "login.qml")
url = QUrl.fromLocalFile(login_file)
def handle_object_created(obj, obj_url):
if obj is None and url == obj_url:
QCoreApplication.exit(-1)
engine.objectCreated.connect(handle_object_created, Qt.QueuedConnection)
engine.load(url)
sys.exit(app.exec())
if __name__ == "__main__":
main()
once the login page opens up now for switching rest of the screens, I use javascript function I wrote in all my qml files to switch to next screen. Following is the JS code I am using for switching to next screen.
function switch_to_test(access) {
if (access == true) {
var component = Qt.createComponent("test_interface_dark_debug.qml")
var win = component.createObject()
win.show()
visible = false
}
else {
console.log('Invalid Credentials')
}
}
And this is causing my UI to crash as I reach test screen. So is there a way to efficiently switching the screens without my UI crashing? I found out this explanation for the crashing of my UI, but I don't know how to resolve the issue. Thank you