Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1207

QTextDocument.createObject() crashes with PySide2

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.14.0
    • PySide
    • None
    • Windows
    • ca5496ab7360a257e81dbc9d8bac653154af7dd3 (pyside/pyside-setup/5.14)

    Description

      I make sure this bug happens with PySide2 , not in PyQt5 and C++ Qt.

      With PySide2, if I subclass QTextDocument, and override createObject, kernel stops.

      This is the PySide2 Version as the Code of

      https://code.woboq.org/qt5/qtbase/src/gui/text/qtextdocument.cpp.html#_ZN13QTextDocument12createObjectERK11QTextFormat

      A specialist recommended I report this bug for the future.

       

       The way of avoiding this bug is to use self.obj instead of obj.

      or append the obj into a container.

      PySide2 trashes the local variable soon. 

       

      from PySide2 import QtWidgets
      from PySide2 import QtGui
      from PySide2 import QtCore
      import PySide2
      import sys
      import os
      dirname = os.path.dirname(PySide2.__file__)
      plugin_path = os.path.join(dirname, 'plugins', 'platforms')
      os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
      class TextEdit(QtWidgets.QTextEdit):
          def __init__(self, parent=None):
              super(TextEdit, self).__init__(parent=None)
              document = TextDocument(self)
              self.setDocument(document)            
      class TextDocument(QtGui.QTextDocument):
          def __init__(self, parent=None):
              super(TextDocument, self).__init__(parent=None)      
              self.setParent(parent)    
          def createObject(self, f):
              obj = QtGui.QTextObject(self)
              if f.isListFormat():
                  obj = QtGui.QTextList(self)
              elif f.isTableFormat():
                  obj = QtGui.QTextTable(self)
              elif f.isFrameFormat():            
                  obj = QtGui.QTextFrame(self)                
              return obj       
      def main():
          if QtWidgets.QApplication.instance() is not None:
              app = QtWidgets.QApplication.instance()
          else:
              app = QtWidgets.QApplication([])
          mainwindow = TextEdit()
          mainwindow.show()
          sys.exit(QtWidgets.QApplication.exec_())
      if __name__ == "__main__":
          main()

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            nori Harunori Fujimoto
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes