Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11
-
Hi,
Has anyone used QFileSystemModel with QTreeView (Qt 6.7.2) under Windows 11?
I copy JPG files in Windows Explorer and delete them, then the program hangs. It worked fine under Windows 10.
I wrote a small test program and the result is the same, program hangs. -
Hi,
Has anyone used QFileSystemModel with QTreeView (Qt 6.7.2) under Windows 11?
I copy JPG files in Windows Explorer and delete them, then the program hangs. It worked fine under Windows 10.
I wrote a small test program and the result is the same, program hangs.@Zbigniew-Sch said in Program does not work properly using QFileSystemModel mit QTreeView (Qt 6.7.2) unter Windows 11:
I wrote a small test program and the result is the same, program hangs
You should share it, so others can see what exactly you're doing and reproduce the issue.
-
//////////////////////////////////////////////////////////////////// // Header file //////////////////////////////////////////////////////////////////// #include <QtWidgets/QMainWindow> #include <QFileSystemModel> class QTreeView; class QFileSystemModel; class QBoxLayout; class QModelIndex; class TestFileSystemModel : public QMainWindow { Q_OBJECT public: TestFileSystemModel(QWidget *parent = nullptr); ~TestFileSystemModel(); QTreeView *m_pcoTreeView; QFileSystemModel *m_pcoModel; QWidget *m_pcoMainWidget; QBoxLayout* m_pcoMainLayout; QModelIndex m_coRootModelIndex; }; //////////////////////////////////////////////////////////////////// // Cpp program //////////////////////////////////////////////////////////////////// TestFileSystemModel::TestFileSystemModel(QWidget *parent) : QMainWindow(parent) { resize(1400, 800); show(); m_pcoModel = new QFileSystemModel(this); m_pcoMainWidget = new QWidget(this); m_pcoMainLayout = new QHBoxLayout(); m_pcoMainLayout->setContentsMargins(0, 0, 0, 0); m_pcoTreeView = new QTreeView(m_pcoMainWidget); m_pcoTreeView->resize(width(), height()); m_coRootModelIndex = m_pcoModel->setRootPath("D:\\TestFolder"); m_pcoTreeView->setModel(m_pcoModel); m_pcoTreeView->setRootIndex(m_coRootModelIndex); m_pcoMainWidget->setLayout(m_pcoMainLayout); this->setCentralWidget(m_pcoMainWidget); } TestFileSystemModel::~TestFileSystemModel() { delete m_pcoMainWidget; delete m_pcoTreeView; delete m_pcoMainLayout; delete m_pcoModel; }
-
//////////////////////////////////////////////////////////////////// // Header file //////////////////////////////////////////////////////////////////// #include <QtWidgets/QMainWindow> #include <QFileSystemModel> class QTreeView; class QFileSystemModel; class QBoxLayout; class QModelIndex; class TestFileSystemModel : public QMainWindow { Q_OBJECT public: TestFileSystemModel(QWidget *parent = nullptr); ~TestFileSystemModel(); QTreeView *m_pcoTreeView; QFileSystemModel *m_pcoModel; QWidget *m_pcoMainWidget; QBoxLayout* m_pcoMainLayout; QModelIndex m_coRootModelIndex; }; //////////////////////////////////////////////////////////////////// // Cpp program //////////////////////////////////////////////////////////////////// TestFileSystemModel::TestFileSystemModel(QWidget *parent) : QMainWindow(parent) { resize(1400, 800); show(); m_pcoModel = new QFileSystemModel(this); m_pcoMainWidget = new QWidget(this); m_pcoMainLayout = new QHBoxLayout(); m_pcoMainLayout->setContentsMargins(0, 0, 0, 0); m_pcoTreeView = new QTreeView(m_pcoMainWidget); m_pcoTreeView->resize(width(), height()); m_coRootModelIndex = m_pcoModel->setRootPath("D:\\TestFolder"); m_pcoTreeView->setModel(m_pcoModel); m_pcoTreeView->setRootIndex(m_coRootModelIndex); m_pcoMainWidget->setLayout(m_pcoMainLayout); this->setCentralWidget(m_pcoMainWidget); } TestFileSystemModel::~TestFileSystemModel() { delete m_pcoMainWidget; delete m_pcoTreeView; delete m_pcoMainLayout; delete m_pcoModel; }
There is so much unnecessary stuff going on in your code...
and maybe you describe what you are doing before it "hangs" or when it crashes?#include <QFileSystemModel> class QFileSystemModel;
Why forward-declare if you include it anyway?
resize(1400, 800); show(); // ... // ... this->setCentralWidget(m_pcoMainWidget);
Why
show()
before the content is created and the centralWidget is set?!
The human eye is probably not able to spot any difference since it might be just milisecs, but the other way round would be better.m_pcoTreeView->resize(width(), height());
Resizing a widget in a layout might have no effect, since the size is managed by the layout and size hints.
delete m_pcoMainWidget; delete m_pcoTreeView; delete m_pcoMainLayout; delete m_pcoModel;
No need to delete any of these widgets manually. They are all childs or grandchildren of your
TestFileSystemModel
QMainWindow
.
So they will be removed with their parentQObject
. -
Thanks for the tips, but that's not the problem.
The program runs and I copy 2-3 JPG files and then I delete them in the directory "D:\TestFolder"
(not in my program) in Windows Explorer and now the program hangs -
Thanks for the tips, but that's not the problem.
The program runs and I copy 2-3 JPG files and then I delete them in the directory "D:\TestFolder"
(not in my program) in Windows Explorer and now the program hangs@Zbigniew-Sch said in Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11:
then I delete them in the directory "D:\TestFolder"
(not in my program) in Windows Explorer and now the program hangsUsually the
QFileSystemModel
has an internalQFileSystemWatcher
which keeps track of changes made to the files.
If the same code works on Win 10 and everywhere else, it's maybe a bug. -
Are you from the Qt development team?
Maybe someone from the Qt development team would like to comment on this problem. -
Are you from the Qt development team?
Maybe someone from the Qt development team would like to comment on this problem.@Zbigniew-Sch said in Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11:
Are you from the Qt development team?
This is a user forum... most people here are users like you with more or less experience.
Debug your app to see why and where it crashes.
If you think it's a bug related toQFileSystemModel
and Win11, create a bugreport here