SHARE
TWEET

Qt issue C++/QML

ExpertDev Jul 21st, 2019 (edited) 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. I want to access model data in c++, not in qml
  2. Below is the code.
  3.  
  4. QHash<int, QByteArray> XItemList::roleNames() const noexcept override
  5. {
  6.     static auto roles = QHash<int, QByteArray>{
  7.         { ID, "id" },
  8.         { Name, "name" },
  9.         { Size, "size"}
  10.     };
  11.  
  12.     return roles;
  13. }
  14.  
  15. QVariant XItemList::data(const QModelIndex &idx, int role) const override
  16. {
  17.     ...
  18.     switch(role)
  19.     {
  20.     case ID:
  21.         ...
  22.         return XXX;
  23.         break;
  24.     case Name:
  25.         ...
  26.         return XXX;
  27.         break;
  28.     case Size:
  29.         ...
  30.         return XXX;
  31.         break;
  32.     }
  33.     ...
  34. }
  35.  
  36.  
  37.  
  38. ListView {
  39.     model: controller.itemlist
  40.  
  41.     delegate: Rectangle {
  42.  
  43.         Label {
  44.             ...
  45.             text: modelData.id
  46.         }
  47.        
  48.  
  49.         Label {
  50.             ...
  51.             text: modelData.item_name
  52.         }
  53.  
  54.         Label {
  55.             ...
  56.             text: modelData.size
  57.         }
  58.     }
  59. }
  60.  
  61. ...
  62. ...
  63. XItemList item_list = container->getXItemList();
  64. here I want to get list of all data of item_list
  65. How can I do that?
  66.  
  67. The result I want looks like this
  68. QList<XItem> result_list;
  69. and each XItem contains id, name and size
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top