Hi, I have strange problem. I have two class: mainWindow inherits by QMainWindow, and myWidget inherits by QWidget. In mainWindow class i create model, and myWidget class i create QTableView. Now i would like copy selection, but not in myWidget, only mainWindow class, so i did something like this in myWidget:
Qt Code:
  1. connect(table->selectionModel(),SIGNAL(
  2. selectionChanged(const QItemSelection &,const QItemSelection &)),
  3. this,SIGNAL(updateSelect(const QItemSelection &,const QItemSelection &)));
To copy to clipboard, switch view to plain text mode 

And in mainWindow:
Qt Code:
  1. connect(widget,SIGNAL(updateSelect(const QItemSelection &,const QItemSelection &)),
  2. this,SLOT(updateSelection(const QItemSelection&,const QItemSelection &)));
  3.  
  4. void mainWindow::updateSelection(const QItemSelection &selection,const QItemSelection &){
  5. this->selection = selection;
  6. }
  7.  
  8. void mainWindow::copyCells(){
  9. QList<QItemSelectionRange> models = selection;
  10. if(models.isEmpty())
  11. return;
  12. QModelIndex start = models[0].topLeft();
  13. QModelIndex stop = models[0].bottomRight();
  14. QString text;
  15. for(int i=start.row(); i<=stop.row(); ++i) {
  16. for(int j=start.column(); j<=stop.column(); ++j) {
  17. if(model->item(i,j)->text() != "="){
  18. text+= model->item(i,j)->text();
  19. text += ' ';
  20. }
  21. }
  22. text += '\n';
  23. }
  24. QApplication::clipboard()->setText(text);
  25. }
To copy to clipboard, switch view to plain text mode 
Now, when i select an area and try copy, it copy random value, further only one left or right column, or top or bottom row. Function copyCells works well, i tested it earlier. Where I make error?