Results 1 to 2 of 2

Thread: how to add model to different model-delegate

  1. #1
    Join Date
    May 2013
    Posts
    45
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default how to add model to different model-delegate

    Hi.
    i have ListView with model in main.qml where is loaded second qml with data. But when i want data from second model they still looking into first model (groupModel) in main.qml. How to get data from itemModel?
    model is in c++. it finish with ReferenceError: datafromItemModelis not defined becouse datafromItemModel is defined in itemModel and he still looking into groupModel

    here is little example:

    main.qml
    Qt Code:
    1. ListView {
    2. id: listView
    3. anchors.fill: parent
    4. model: groupModel
    5.  
    6. delegate: Loader {
    7. source: fileName // fileName from groupModel data
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    item.qml
    Qt Code:
    1. GridView {
    2. model: itemModel
    3.  
    4. delegate: Rectangle {
    5. Text {
    6. text: datafromItemModel
    7. }
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    c++ code
    Qt Code:
    1. QVariant MainModel::data(const QModelIndex & index, int role) const
    2. {
    3. const ItemModel * itemModel= mainDatas.at(index.row());
    4. switch (role)
    5. {
    6. case fileNameRole:
    7. return QString("item.qml");
    8. case itemModelRole:{
    9. return itemModel;
    10. }
    11. default:
    12. return QVariant();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by stevocz; 16th February 2018 at 13:00.

  2. #2
    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: how to add model to different model-delegate

    Do you mean that one model serves data which is instances of the other model?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 5th February 2014, 16:39
  2. Replies: 1
    Last Post: 29th August 2013, 06:41
  3. model view delegate
    By waiter in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2012, 08:21
  4. Model/Delegate/Proxy
    By skyline2000 in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2011, 17:13
  5. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 7th November 2008, 00:00

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.