The problem is that when calling the function through the completion of entering text into the input string, it works fine, but when it is activated by an event of pressing key, the code works, but it crashes on the call of the "setUrl" method. In other words, the variable changes its text but then the program immediately crashes with the message: "Process finished with exit code -2147483645".
The method from this solution is too old and those methods are not working.
Here is my code:
import sysfrom PyQt6.QtCore import QUrlfrom PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QLineEdit, QLabelfrom PyQt6.QtWebEngineWidgets import QWebEngineViewfrom PyQt6 import uicimport keyboardapp = QApplication(sys.argv)window = QMainWindow()uic.loadUi("data/new.ui", window)window.setWindowTitle("PyQt6 with QWebEngineView")# window.setGeometry(100, 100, 900, 900) # 800, 600# TODO: main widgetcentral_widget = window.findChild(QWidget, "centralwidget")layout = QVBoxLayout(central_widget)layout_ = window.findChild(QVBoxLayout, "verticalLayout")# TODO: line-editweb_edit = window.findChild(QLineEdit, "web_edit")# TODO: web_windowweb_view = window.findChild(QWebEngineView, "webEngineView")web_view.setUrl(QUrl("https://www.example.com"))# TODO: eventsdef change_url(): lb_edit.setText("test") # for test the function call web_view.setUrl(QUrl.fromLocalFile("/config/config.html")) # here is the code break'slb_edit = window.findChild(QLabel, "label")web_edit.returnPressed.connect(change_url)hotkey_ = 'c'keyboard.add_hotkey(hotkey_, change_url)window.show()sys.exit(app.exec())
When the issue initially arose in the main program, I moved this code to another program where I also worked with QWebEngineView. As a result, when the event is triggered by the keyboard, everything before "web_view.setUrl(QUrl.fromLocalFile("/config/config.html"))" works, but this line does not work and the code immediately crashes.