Sample Code of SimpleTreeModel
-
I try to use this code in my App.
@QFile file(":/default.txt");
file.open(QIODevice::ReadOnly);
TreeModel model(file.readAll());
file.close();QTreeView view;
view.setModel(&model);
view.setWindowTitle(QObject::tr("Simple Tree Model"));
view.show();@when I paste it in main then code works (I see QTreeView with data), but when paste it in QMainWindow constructor then I see an empty QTreeView window without data.
why?
-
QTreeModel and QTreeView are destroyed when QMainWindow constructor is finished. Use "new" to create these objects
-
ups!