2017-09-23 48 views
0

導航到空目錄時,我收到以下有關無效索引的控制檯垃圾郵件。我得到一個稍微不同的消息,這取決於父目錄的哪一列被雙擊以進入空目錄。雙擊名稱列後,在進入空目錄後,單擊表格中的任意位置,將導致第一組垃圾(10)。如果雙擊其他列,則會發生1 1,1 2,1 3消息。QAccessibleTable :: child:使用QTableView和QFileSystemModel的空目錄中的索引無效

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和5.7.1的PyQt 。

回答

0

升級到pyqt5.9似乎導致問題消失。

相關問題