Results 1 to 5 of 5

Thread: transfering items from one model to the other

  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default transfering items from one model to the other

    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?

  2. #2
    Join Date
    Jan 2008
    Posts
    58
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: transfering items from one model to the other

    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...

  3. #3
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: transfering items from one model to the other

    Quote Originally Posted by cyberboy View Post
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: transfering items from one model to the other

    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).

  5. #5
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: transfering items from one model to the other

    Quote Originally Posted by wysota View Post
    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?

Similar Threads

  1. Edit items in table model
    By gyre in forum Newbie
    Replies: 2
    Last Post: 14th January 2008, 03:08
  2. removing model Items
    By gyre in forum Newbie
    Replies: 2
    Last Post: 25th November 2007, 20:10
  3. Model Choices review/questions
    By ucntcme in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2007, 21:57
  4. Moving items within a model
    By iswm in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2007, 08:29
  5. Limitation when adding more than 256 items to a model
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2006, 15:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.