Hi guys

In this function im trying to connect each QTreeWidgetItem with its corresponding query,
once i select an item a query result in tableview model is shown.

what i want is that when i select a new item the shown tableview hide and new one appears with a new result. what i have until now is that each item i select a new tableview appears . I want to see only one tableview.

here is my function

Qt Code:
  1. void MainWindow::DocumentTable()
  2. {
  3. tableview = new QTableView;
  4. query = new QSqlQueryModel(this);
  5.  
  6. foreach(it,treeWidget->selectedItems())
  7. {
  8. for (int col=0; col< it->columnCount(); ++col)
  9. {
  10. qDebug() << col << it->text(col);
  11.  
  12. QSqlQuery qry;
  13. qry.prepare("select * from document where Folno=:Folno");
  14. qry.bindValue(":Folno", it->text(col));
  15. qry.exec();
  16.  
  17. query->setQuery(qry);
  18.  
  19. tableview->setModel(query);
  20. tableview->setEditTriggers(QAbstractItemView::NoEditTriggers);
  21. tableview->show();
  22.  
  23. Docwidget= new QDockWidget(this);
  24. Docwidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
  25.  
  26. Docwidget->setWidget(tableview);
  27. addDockWidget(Qt::RightDockWidgetArea,Docwidget);
  28. Docwidget->show();
  29.  
  30.  
  31. if(!query->submit())
  32. {
  33. qDebug() << "Error " << query->lastError().text();
  34. }
  35.  
  36. db.close();
  37.  
  38. }
  39. }
  40. }
To copy to clipboard, switch view to plain text mode 

any ideas ??