From f26f8c0a1a569a1397c3dde1f3fd7d0d7795f1f6 Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 29 Jul 2013 16:16:00 +0200 Subject: Another shot at the Filesystem View crashes I think I found the bug. We need to stop the refresh timer when operating on the view, because it can reset the model while we're still holding QModelIndexes. When that happens we're working with invalid indexes and BOOM. --- filesystemwidget.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'filesystemwidget.cpp') diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 4c05640..317d9c2 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -163,13 +163,21 @@ void FilesystemWidget::directoryEdited(){ } void FilesystemWidget::fileViewActivated(const QModelIndex &idx){ - QModelIndex real = mFileProxy->mapToSource(idx); + /* we cannot use idx from the SIGNAL here, since the model + * may already have changed */ + Q_UNUSED(idx); + TimerHandler h(mFileModel->refresTimer()); + QModelIndexList selected = mFileView->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return; + } + QModelIndex real = mFileProxy->mapToSource(selected.first()); if(mFileModel->isDir(real)){ - if(idx.data().toString() == ".."){ + if(real.data().toString() == ".."){ parentDir(); return; } - fileView()->selectionModel()->select(idx, QItemSelectionModel::Deselect); + fileView()->selectionModel()->select(selected.first(), QItemSelectionModel::Deselect); QModelIndex curDir = mModel->index(real.data(SmDirModel::FullPathRole).toString()); mDirView->setCurrentIndex(mDirProxy->mapFromSource(curDir)); return; @@ -216,6 +224,7 @@ void FilesystemWidget::goBack(){ } void FilesystemWidget::deleteFiles(){ + TimerHandler h(mFileModel->refresTimer()); QSortFilterProxyModel *proxy = qobject_cast(mFileView->model()); QModelIndexList selected = mFileView->selectionModel()->selectedRows(); if(selected.isEmpty()){ @@ -233,6 +242,7 @@ void FilesystemWidget::deleteFiles(){ } void FilesystemWidget::toClipboard(int clipmode){ + TimerHandler h(mFileModel->refresTimer()); mClipboardMode = clipmode; QClipboard *clip = qApp->clipboard(); QModelIndexList selected = mFileView->selectionModel()->selectedRows(); @@ -279,7 +289,7 @@ void FilesystemWidget::fromClipboard(){ } void FilesystemWidget::renameFile(){ - mFileModel->refresTimer()->stop(); + TimerHandler h(mFileModel->refresTimer()); QModelIndex curIdx = mFileView->currentIndex(); if(curIdx.data().toString() == ".."){ return; @@ -288,6 +298,7 @@ void FilesystemWidget::renameFile(){ } void FilesystemWidget::playSelected(const QString &player){ + TimerHandler h(mFileModel->refresTimer()); QStringList files = selectedFiles(); if(files.isEmpty()){ statusbarMessage(tr("Nothing selected.")); -- cgit v1.2.3-70-g09d2