I am trying to write a python macro for libre office 7.4 on windows 10 that creates a dialog with pyqt6.
def open_qt_dialog():
import sys
from PyQt6.QtWidgets import (
QApplication,
QWidget,
)
app = QApplication([])
window = QWidget()
window.setWindowTitle("Simple Dialog")
window.show()
sys.exit(app.exec())
Regardless of whether I use a QDialog or a QMainWindow, I get the following error when I press the "X" button in the title bar. After that the dialog is closed.
com.sun.star.uno.RuntimeException: <class 'SystemExit'>: 0, traceback follows
File "C:\Program Files\LibreOffice\program\pythonscript.py", line 915, in invoke
ret = self.func( *args )
File "C:\Users\<username>\AppData\Roaming\LibreOffice\4\user\Scripts\python\Test.py", line 101, in open_qt_dialog
sys.exit(app.exec())
If I then run the macro again, the dialog is called again and shortly after that libre office crashes. This behavior occurs regardless of whether the macro is executed via the menu or via a button.
Only closing the dialog seems to be a problem. Interaction with libre office (e.g. writing a value into a cell, when pressing a button) works so far. I already tried to overwrite the closeEvent method using the quit method on the mainwindow. But it just closed (or crashed) the whole libre office application. Do i mess anything? Do I still have to adjust the sys.exit command in any way? I have the suspicion that sys.exit tries to close libre office completely and not the dialog itsself.
If I run the script via pycharm (connected to uno via uno bridge), then I can close the dialog without any problems.
sys.exit()and just callapp.exec().app = QApplication.instance()and addif not app:app = QApplication()right after that. Also try to adddel appafterapp.exec().