导航到空目录时,我收到以下有关无效索引的控制台垃圾邮件。我得到一个略有不同的消息,取决于双击父目录的哪一列到达空目录。双击“名称”列会在输入空目录后单击表中的任何位置时导致第一组垃圾邮件(1 0)。如果双击其他列,则会出现1 1,1 2,1 3消息。
QAccessibleTable::child: Invalid index at: 1 0
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 11
QAccessibleTable::child: Invalid index at: 1 0
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 11
QAccessibleTable::child: Invalid index at: 1 0
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 11
QAccessibleTable::child: Invalid index at: 1 1
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 12
QAccessibleTable::child: Invalid index at: 1 1
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 12
QAccessibleTable::child: Invalid index at: 1 1
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 12
QAccessibleTable::child: Invalid index at: 1 2
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 13
QAccessibleTable::child: Invalid index at: 1 2
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 13
QAccessibleTable::child: Invalid index at: 1 2
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 13
QAccessibleTable::child: Invalid index at: 1 3
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 14
QAccessibleTable::child: Invalid index at: 1 3
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 14
QAccessibleTable::child: Invalid index at: 1 3
Cannot creat accessible child interface for object: QTableView(0x5651e6c1edd0) index: 14
我已尝试移动setRootIndex()调用的位置,但它没有帮助。是否有其他应该做的事情?
此代码似乎有效,但我之前(PyQt5 Crash with QFileSystemModel and QSortFilterProxyModel..doing something wrong?)发现了与此垃圾邮件相关的随机崩溃。
import os, sys, tempfile
from PyQt5 import QtCore, QtWidgets
print(QtCore.qVersion())
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
layout = QtWidgets.QVBoxLayout()
self.setLayout(layout)
self._view = QtWidgets.QTableView()
layout.addWidget(self._view)
self._model = QtWidgets.QFileSystemModel()
self._model.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.NoDot)
self._view.setModel(self._model)
self._view.doubleClicked.connect(self._double_clicked)
# Create a temporary directory structure (tmpxyz/foo) starting at the location of this file
path = os.path.dirname(os.path.abspath(__file__))
self.temp_dir = tempfile.TemporaryDirectory(dir=path)
print('created temporary directory', self.temp_dir.name)
foo_dir = os.path.join(self.temp_dir.name, 'foo')
os.mkdir(foo_dir)
self.parentIndex = self._model.setRootPath(foo_dir)
# self._set_view_root(self.parentIndex) # Same spam whether called here or deferred to _loaded
self._model.directoryLoaded.connect(self._loaded)
def _set_view_root(self, source_index):
self._view.setRootIndex(source_index)
def _loaded(self):
path = self._model.rootPath()
source_index = self._model.index(path)
self._set_view_root(source_index)
print('_loaded', path, self._model.rowCount(self.parentIndex))
def _double_clicked(self, index):
info = self._model.fileInfo(index)
absolute_path = info.absoluteFilePath()
print('_double_clicked', absolute_path)
if info.isDir():
self.parentIndex = self._model.setRootPath(absolute_path)
# self._set_view_root(self.parentIndex)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
widget = Widget()
widget.show()
sys.exit(app.exec_())
我在一个干净的虚拟环境中使用Python 3.6.1,PyQt5 == 5.8.2在Ubuntu 17.04上,但我在基础Ubuntu上使用Python 3.5.3和PyQt 5.7.1获得相同的行为。< / p>
答案 0 :(得分:0)
升级到pyqt5.9似乎已经解决了问题。