Hello,

I am updating some code to use PyQt-Py2.6-x86-gpl-4.9.4-1.exe. I have previously used PyQt-Py2.6-x86-gpl-4.8.6-1.exe. With the code attached I get a runtime error in 4.9.4 I did not get in the 4.8.6.

Please execute the attached py file and click the open button in the window appearing. This opens a dialog. Close the dialog and click the signal button. Here I am getting an error:

Traceback (most recent call last):
  File "pyqt_runtimeerror.py", line 50, in check
    print "test checked", self.isChecked()
  File "pyqt_runtimeerror.py", line 28, in isChecked
    return self.checkBox.isChecked()
RuntimeError: wrapped C/C++ object of %S has been deleted


To get rid of the problem I can comment line 8 (self.dialog = parent). Is this something I should fix in my app and was the 4.8.6 behaviour unintened or is this a bug?

Cheers

Sebastian

from PyQt4.QtGui import QMainWindow, QApplication, QCheckBox, QPushButton, QDialog, QVBoxLayout, QWidget, QHBoxLayout
from PyQt4.QtCore import Qt, QAbstractItemModel, pyqtSignal

class MyTreeModel(QAbstractItemModel):

    def __init__(self, parent):
        QAbstractItemModel.__init__(self, parent)
        self.dialog = parent

    def columnCount(self, parent):
        return 0

    def rowCount(self, parent):
        return 0

class BaseDialog(QDialog):

    def __init__(self, parent):
        QDialog.__init__(self, parent)
        self.checkBox = None

    def addCheckbox(self):
        self.checkBox = QCheckBox("checkbox")
        self.layout().insertWidget(self.layout().count() - 1, self.checkBox)

    def isChecked(self):
        if self.checkBox:
            return self.checkBox.isChecked()
        else:
            return False

class Dialog(BaseDialog):

    def __init__(self, parent):
        """Dialog to add or edit notes"""
        BaseDialog.__init__(self, parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.mainWindow = parent

        self.treeModel = MyTreeModel(self)

        self.mainWindow.mySignal.connect(self.check)

        hBoxLayout = QVBoxLayout()
        self.setLayout(hBoxLayout)

        self.addCheckbox()

    def check(self):
        print "test checked", self.isChecked()

class MainWindow(QMainWindow):

    mySignal = pyqtSignal()

    def __init__(self):
        QMainWindow.__init__(self)

        centralWidget = QWidget()
        hBoxLayout = QHBoxLayout()
        centralWidget.setLayout(hBoxLayout)
        self.setCentralWidget(centralWidget)
        self.openButton = QPushButton("open")
        self.openButton.clicked.connect(self.openDialog)
        hBoxLayout.addWidget(self.openButton)
        self.signalButton = QPushButton("signal")
        self.signalButton.clicked.connect(self.mySignal)
        hBoxLayout.addWidget(self.signalButton)

    def openDialog(self):
        dlg = Dialog(self)
        dlg.show()

app = QApplication([])
mainWindow = MainWindow()
mainWindow.show()
app.exec_()
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to