Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.15.2, 6.2.0 Alpha
-
-
f6bca6261156e8f648bf7d41ba1728ef17cd6889 (qt/qtbase/dev) ba0bca338c4fa743b007a4c4f204f09f9e5a8a80 (qt/tqtc-qtbase/5.15) 8df72123254277454f46945171194d1aa945b1d2 (qt/qtbase/6.1) 96222ec18c0e14995ae843cde9faf8a1b96d4943 (qt/qtbase/6.2)
Description
Issue
When the model is asynchronous (like QFileSystemModel, or the example model at https://code.qt.io/cgit/qt/qtopcua.git/tree/examples/opcua/opcuaviewer ), expandToDepth() might stop expanding before the desired depth is reached.
The same occurs with expandAll().
Demo
#include <QtWidgets> int main(int argc, char *argv[]) { QApplication a(argc, argv); auto model = new QFileSystemModel; model->setRootPath("C:/tmp"); QTreeView tree; tree.setModel(model); QPushButton button("Click me to expand"); QObject::connect(&button, &QPushButton::clicked, [&]{ tree.expandToDepth(3); }); tree.show(); button.show(); return a.exec(); }
- Expected behaviour: 1 click should expand the tree to depth 3
- Actual behaviour: Multiple clicks are required to reach depth 3 (Although depending on your filesystem size, the last click will likely freeze the app)
Workaround
Call `expandToDepth(depth)` repeatedly (with a slight wait between each call) until the desired depth is reached. Each call causes the model to fetch a bit more data, so it allows expansion to proceed a bit further.