qt - QTreeView closes immediately -
i want display qtreeview
when user choses qaction
menu of mainwindow
(which agendawindow
in case).
the issue when click on button display it, opens qtreeview
, closes immediately. put infinite loop (while(1<2))
program blocked , couldn't find equivalent system("pause")
.
here function:
void agendawindow::display_projects() { qstandarditemmodel* model = new qstandarditemmodel; qstandarditem *parentitem= model->invisiblerootitem(); (std::vector<projet*>::const_iterator =pm.getinstance().gettab().begin(); it!= pm.getinstance().gettab().end(); it++ ) { // display project qstandarditem* item=new qstandarditem(qstring((*it)->gettitre())); item->setflags(item->flags() & ~qt::itemiseditable); parentitem->appendrow(item); projet* p = (*it); // display every project's tasks (std::vector<tache*>::const_iterator itp = p->gettabprojet().begin(); itp != p->gettabprojet().end(); itp++) { qstandarditem* itemp = new qstandarditem((*itp)->gettitre()); //itemp->setflags(itemp->flags() & ~qt::itemiseditable); item->appendrow(itemp); } } qtreeview *treeview=new qtreeview; treeview->setmodel(model); treeview->show(); //while(1<2); }
thank you!
update: answer wrong. object on heap not stack. there's potential memory leak though.
the qtreeview creating local method. when goes out of scope (when method ends) destroyed. need have qtreeview maybe member of class , call show method when convenient.
it seems lack basics regarding qt , gui. read qt event loop.
Comments
Post a Comment