[Solved]QTreeView based on MVC Pattern
I read some articles about MVC, better to say MV, design pattern in Qt and used the Simple Tree Model example which is existed as an example in Qt_Examples in my program.
My proram is a MainWindow with different parts and functions. I put the Tree in the QTabWidget:
QTabWidget tabWidget = new QTabWidget;
tabWidget->addTab(new GeneralTab(), tr("General"));
//The writen code in GeneralTab class
QTreeView* treeView = new QTreeView; treeView->setModel(&model); QVBoxLayout* treeLayout = new QVBoxLayout; treeLayout->addWidget(treeView); setLayout( treeLayout);
The problem is nothing will be showen, in my tab!!! even no error message!
I am looking forward to the suggestions esp. solutions:)
your model is a stack variable, which means, it will be deleted on method end.
Make it a heap object created with new :-)
Don't worry, it's a classic mistake :-)
Thank you. It works now:)