代码之家  ›  专栏  ›  技术社区  ›  AkiRoss

如果没有在PySide中指定对象变量,则对象似乎被删除

  •  1
  • AkiRoss  · 技术社区  · 14 年前

    例如

    self.tree_model = QStandardItemModel()
    self.tree_model.setHorizontalHeaderLabels(['Category'])
    self.out_insertions = QStandardItem("Insertions")
    self.tree_model.invisibleRootItem().appendRow(self.out_insertions)
    

    按预期工作(在“类别”列下插入“插入”行)。但如果我删除self.out_插入赋值,例如:

    self.tree_model = QStandardItemModel()
    self.tree_model.setHorizontalHeaderLabels(['Category'])
    self.tree_model.invisibleRootItem().appendRow(QStandardItem("Insertions"))
    

    我用的是Qt 4.6.3和PySide 0.4.1。 有人能解释一下为什么会这样吗?

    提前谢谢

    1 回复  |  直到 14 年前
        1
  •  4
  •   ChristopheD    14 年前

    由于没有更多的(Python)引用,您的对象会被垃圾收集。

    things to be aware of '在PyQt文档中。

    parenting (这使得Qt取代PyQt拥有所有权)。