aboutQt() Runtime Error
-
I am trying to add an About Qt window to my Python Qt app but whenever the function to create it is triggered, it returns this error
aboutQt.aboutQt(aboutQt) RuntimeError: libshiboken: Internal C++ object (PySide6.QtWidgets.QMessageBox) already deleted.Here is the relevant portion of my code:
from PySide6 import QtCore, QtWidgets, QtGui from PySide6.QtUiTools import QUiLoader from PySide6.QtCore import QFile from ui.ui_mainWindow import Ui_MainWindow class mainWindow(QtWidgets.QMainWindow): def __init__(self): super(mainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) class dialogWindow(QtWidgets.QDialog): def __init__(self, windowFile): super(dialogWindow, self).__init__() self.ui = windowFile self.ui.setupUi(self, self) def aboutQtWindow(): global aboutQt aboutQt = QtWidgets.QMessageBox(dialogWindow(ui.ui_aboutQt.Ui_Dialog)) aboutQt.aboutQt(aboutQt) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = mainWindow() window.show() window.ui.actionAbout_Qt.triggered.connect(aboutQtWindow) sys.exit(app.exec()) -
I am trying to add an About Qt window to my Python Qt app but whenever the function to create it is triggered, it returns this error
aboutQt.aboutQt(aboutQt) RuntimeError: libshiboken: Internal C++ object (PySide6.QtWidgets.QMessageBox) already deleted.Here is the relevant portion of my code:
from PySide6 import QtCore, QtWidgets, QtGui from PySide6.QtUiTools import QUiLoader from PySide6.QtCore import QFile from ui.ui_mainWindow import Ui_MainWindow class mainWindow(QtWidgets.QMainWindow): def __init__(self): super(mainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) class dialogWindow(QtWidgets.QDialog): def __init__(self, windowFile): super(dialogWindow, self).__init__() self.ui = windowFile self.ui.setupUi(self, self) def aboutQtWindow(): global aboutQt aboutQt = QtWidgets.QMessageBox(dialogWindow(ui.ui_aboutQt.Ui_Dialog)) aboutQt.aboutQt(aboutQt) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = mainWindow() window.show() window.ui.actionAbout_Qt.triggered.connect(aboutQtWindow) sys.exit(app.exec())@SamuraiDestroy
I believe you will find:aboutQt = QtWidgets.QMessageBox(dialogWindow(ui.ui_aboutQt.Ui_Dialog))creates an anonymous
QDialogtemporarily, makes theQMessageBoxhave that to center on, and then destroys theQDialogso the message box now is to be centered on a non-existent dialog? Might cause the message?aboutQt.aboutQt(aboutQt)don't know what this would do, seems to pass
aboutQtto center on itself? Might cause the message?The method is static aboutQt(parent[, title=""]). So it's static, and I believe it creates and displays the whole "About" dialog. Don't know what your intention to create your own about dialog is about? (If you want to display some dialog of your own as the parent for the
aboutQtmessage box you need to create and show that dialog and keep a reference to it.)I thought you were just supposed to write something like:
QtWidgets.QMessageBox.aboutQt(None)No instances of anything. No dialog of your own.
To center that on the main window, if you want that, you would pass your
window = mainWindow()instance as parent.P.S.
I see there is also a convenience QApplication.aboutQt() method. Soapp.aboutQt()should also work. -
S SamuraiDestroy has marked this topic as solved
-
@SamuraiDestroy
I believe you will find:aboutQt = QtWidgets.QMessageBox(dialogWindow(ui.ui_aboutQt.Ui_Dialog))creates an anonymous
QDialogtemporarily, makes theQMessageBoxhave that to center on, and then destroys theQDialogso the message box now is to be centered on a non-existent dialog? Might cause the message?aboutQt.aboutQt(aboutQt)don't know what this would do, seems to pass
aboutQtto center on itself? Might cause the message?The method is static aboutQt(parent[, title=""]). So it's static, and I believe it creates and displays the whole "About" dialog. Don't know what your intention to create your own about dialog is about? (If you want to display some dialog of your own as the parent for the
aboutQtmessage box you need to create and show that dialog and keep a reference to it.)I thought you were just supposed to write something like:
QtWidgets.QMessageBox.aboutQt(None)No instances of anything. No dialog of your own.
To center that on the main window, if you want that, you would pass your
window = mainWindow()instance as parent.P.S.
I see there is also a convenience QApplication.aboutQt() method. Soapp.aboutQt()should also work.@JonB said in aboutQt() Runtime Error:
I thought you were just supposed to write something like:
QtWidgets.QMessageBox.aboutQt(None)
This works perfectly, thank you