Results 1 to 2 of 2

Thread: how to add model to different model-delegate

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 12:00.

Similar Threads

  1. Replies: 3
    Last Post: 5th February 2014, 15:39
  2. Replies: 1
    Last Post: 29th August 2013, 05:41
  3. model view delegate
    By waiter in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2012, 07:21
  4. Model/Delegate/Proxy
    By skyline2000 in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2011, 16:13
  5. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23: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.