Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.6, 6.7
-
None
-
Windows 10
-
-
a79ca35ab (dev), 32270a127 (6.7)
Description
Hello,
There is problem with deleting QFileSystemModel.
Problems:
- it takes 1s (at least) to delete QFileSystemModel that operates on local file system
- entire GUI thread hangs for that period
Example:
#include <QApplication> #include <QTimer> #include <QElapsedTimer> #include <QFileSystemModel> #include <QTime> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); QFileSystemModel *fs = new QFileSystemModel( &a); fs->setReadOnly( true); fs->setRootPath( QDir::homePath()); QObject::connect ( fs, &QFileSystemModel::directoryLoaded, [fs, &a] () { QElapsedTimer timer; timer.restart(); // fs->setParent( nullptr); // leaks, so no 1s wait and GUI hangs delete fs; qDebug() << "after delete:" << timer.elapsed(); qDebug() << "quiting qApp at:" << QTime::currentTime().toString(); a.quit(); }); return a.exec(); }
Output:
17:15:43: Starting C:\Users\user\Desktop\0\_build-testing\release\testing.exe... after delete: 1014 quiting qApp at: "17:15:44" 17:15:44: C:\Users\user\Desktop\0\_build-testing\release\testing.exe exited with code 0
The root of the issue (I believe) is commit:
https://code.qt.io/cgit/qt/qtbase.git/commit/src?h=6.6.2&id=7e7b502e369646a89070969ab994cea4be9dc0b6
Namely:
-QFileSystemModelPrivate::~QFileSystemModelPrivate() = default; +QFileSystemModelPrivate::~QFileSystemModelPrivate() +{ + fileInfoGatherer->requestInterruption(); + if (!fileInfoGatherer->wait(1000)) { + // If the thread hangs, perhaps because the network was disconnected + // while the gatherer was stat'ing a remote file, then don't block + // shutting down the model (which might block a file dialog and the + // main thread). Schedule the gatherer for later deletion; it's + // destructor will wait for the thread to finish. + auto *rawGatherer = fileInfoGatherer.release(); + rawGatherer->deleteLater(); + } +}
This, probably, fixes networking issue (dunno, didn't tested it) but introduces, IMHO, more sever one (1s hang) that affect all QFileSystemModel operating on local file system.
Work around:
Make it leak by:
QFileSystemModel::setParent( nullptr);
Thanks in advance for looking into it.
Best regards
Attachments
Issue Links
- is duplicated by
-
QTBUG-122719 QFileSystemModel hangs on destruction
-
- Closed
-