从子类QFileSystemModel获取QFileInfo时出现segv

问题描述

上下文:

由于其现有的文件浏览器功能,我正在使用QTableView和子类QFileSystemModel创建目录浏览器。

我正在使用5列,第一列[0]的宽度为128px,其余的宽度分别为type:"category" 我在包含6,9,3,2和{{1 }}。

QTableWidget

问题:

在实现QAbstractItemView::doubleClickQFileSystemModel)来输入目录和set the new root model index时(即浏览到设置的目录)。

双击单元格时:

 [0] Icon (default icon for folder or file,except in the case of an image where the image icon is loaded from cache)
 [1] File name
 [2] File location (relative to a specific directory)
 [3] Last date modified of the file
 [4] File size (formatted to human readable
  • 我在模型中查询fileInfo条目(由于QTableView无法正常工作,因此创建了一个get方法用于测试)。

     // Connect on list widget cell click to browse into directory or open file
     connect(ui->customTableView,&QTableView::doubleClicked,this,[this](const QModelIndex & index) {
          QFileInfo fi = model->getFileInfo(index);
          QString newPath = fi.filePath();
          changeDirectory(newPath);
     });
    
  • 在模型内部,我使用fileInfo(const QModexIndex&)请求 QFileInfo FileSystemModel::getFileInfo(const QModelIndex& index) { QFileInfo mfileInfo = QFileInfo(fileInfo(index)); return mfileInfo; } 对象,然后在共享指针上生成segv。

请参阅下面的详细信息。

调试器输出

QFileInfo

堆栈跟踪输出

fileInfo(index)

崩溃图片

enter image description here

完整代码示例 (主要根据hereLocals index @0x32d3dfd0 QModelIndex & c 1 int i 853000288 quintptr m @0x32d7a548 FileSystemModel [QFileSystemModel] @0x32d7a548 QFileSystemModel [d] @0x32d79b58 QFileSystemModelPrivate [parent] 0x0 QObject * [children] <0 items> [properties] <at least 0 items> [methods] <0 items> [extra] COLUMN_DATE_MODIFIED 3 int COLUMN_FILENAME 1 int COLUMN_ICON 0 int COLUMN_LOCATION 2 int COLUMN_SIZE 4 int dataPath "H:/debug/Root" QString locale @0x32d7a558 QLocale mimeDb @0x32d7a550 QMimeDatabase staticMetaObject @0x53a4c0 QMetaObject r 0 int mfileInfo <not accessible> QFileInfo this 0xbaadf00d FileSystemModel* Inspector Expressions Return Value Tooltip 找到)

头文件

1   QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData>>::operator->                                                                                                                                                   qscopedpointer.h          118  0x207175ea 
2   qGetPtrHelper<QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData>>>                                                                                                                                                qglobal.h                 1055 0x207175ea 
3   QFileSystemModel::d_func                                                                                                                                                                                                      qfilesystemmodel.h        152  0x207175ea 
4   QFileSystemModel::fileInfo                                                                                                                                                                                                    qfilesystemmodel.cpp      169  0x207175ea 
5   FileSystemModel::getFileInfo                                                                                                                                                                                                  filesystemmodel.cpp       85   0x48ca6a   
6   ExplorerDialog::<lambda(const QModelIndex&)>::operator()(const QModelIndex &) const                                                                                                                                           ExplorerView.cpp          418  0x44e3e6   
7   QtPrivate::FunctorCall<QtPrivate::IndexesList<0>,QtPrivate::List<const QModelIndex&>,void,ExplorerDialog::setupListWidget()::<lambda(const QModelIndex&)>>::call(ExplorerDialog::<lambda(const QModelIndex&)> &,void * *) qobjectdefs_impl.h        146  0x45b0e9   
8   QtPrivate::Functor<ExplorerDialog::setupListWidget()::<lambda(const QModelIndex&)>,1>::call<QtPrivate::List<QModelIndex const&>,void>(ExplorerDialog::<lambda(const QModelIndex&)> &,void *,void * *)                     qobjectdefs_impl.h        256  0x45aca1   
9   QtPrivate::QFunctorSlotObject<ExplorerDialog::setupListWidget()::<lambda(const QModelIndex&)>,1,void>::impl(int,QtPrivate::QSlotObjectBase *,QObject *,void * *,bool *)            qobjectdefs_impl.h        439  0x459f5b   
10  QtPrivate::QSlotObjectBase::call                                                                                                                                                                                              qobjectdefs_impl.h        394  0x65c8161  
11  QMetaObject::activate                                                                                                                                                                                                         qobject.cpp               3789 0x65c8161  
12  QMetaObject::activate                                                                                                                                                                                                         qobject.cpp               3660 0x65c851b  
13  QAbstractItemView::doubleClicked                                                                                                                                                                                              moc_qabstractitemview.cpp 661  0x207519a6 
14  QAbstractItemView::mouseDoubleClickEvent                                                                                                                                                                                      qabstractitemview.cpp     1964 0x2075dd0a 
//...

和实施

::data()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...