0

我正在尝试访问Qt通过 .ui 文件加载的元素。但是我收到错误:

AttributeError: 'TreeviewWidgetSelectProve' object has no attribute '_treeview'

这些链接中分别提供了完整的python 代码.ui 文件。代码片段:

    ui_file_path = os.path.join(
        '/home/userdaze/pyside_test', 'resource', 'treeview.ui')

    loader = QUiLoader(self)
    ui_file = QFile(ui_file_path)
    self._widget_top = loader.load(ui_file, self)

    self._treeview = self._widget_top.findChild(QTreeView, '_treeview')
    self._treeview.setModel(self._std_model)

我是否在此线程中使用findChild建议并不会改变这种情况。如果正在使用它会返回。NoneType

怎么了?谢谢!

Ubuntu Quantal 上的 python-pyside 1.1.1-3

4

1 回答 1

2

恐怕您的 .ui 文件已损坏。您是否尝试在 QtDesigner 中打开它?当我这样做时,它会报告错误。所以我用 QtDesigner 重新创建了文件(只是一个带有 QTreeView 的 QMainWindows),你的问题就消失了。

不过还有很多其他问题:

于 2013-03-01T17:10:25.297 回答