PDA

View Full Version : transfering items from one model to the other



ru_core
26th June 2008, 19:27
Hello,

there are two models (QStandardItemModel). One of them has the item (Item1) with child items which also have child items.

The task is to cut that child items from one model (from Item1) and insert it to the definite item in the other model as a children.

Are there any standard ways of who to do it?

cyberboy
26th June 2008, 20:59
I think you just have to read the data from the model and insert it into the other model with a for loop. And I just read a book about models and tables in Qt and they prefer usage of QAbstractTableModel instead of QStandardItemModel. I don't know the exact reason...

ru_core
26th June 2008, 21:48
I think you just have to read the data from the model and insert it into the other model with a for loop. And I just read a book about models and tables in Qt and they prefer usage of QAbstractTableModel instead of QStandardItemModel. I don't know the exact reason...


1) thank you for the reply. Let me know please, you mean to read data (just get data) from one model, then - create the items in the othe with read data? And then I have to delete read data in the first model?

2) what book have you read about the models and who prefer to use QAbstractItemModel instead of QStandardItemModel?

wysota
26th June 2008, 22:50
I'd try using QStandardItemModel::takeItem() to remove the item from one model and then inserting it into the other. If you want a copy, you can clone the item instead of taking it out of the model (remember that clone() doesn't copy child items so you have to do it manually).

ru_core
27th June 2008, 09:44
I'd try using QStandardItemModel::takeItem() to remove the item from one model and then inserting it into the other. If you want a copy, you can clone the item instead of taking it out of the model (remember that clone() doesn't copy child items so you have to do it manually).

Thank you very much for the reply.

Let me know please, does QStandardItemModel::takeItem() takes the child items (appended to taken) or not?