Results 1 to 4 of 4

Thread: QMap model data

  1. #1
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QMap model data

    Hi...Im trying to imeplement a model that would store some statistics
    I wanted to use QMap to store count as a value of QMap item under a certain key...
    The problem is that I dont know ho to implement a data() method of the model to get the data from actual index...since the QMap doesnt store the data as they are inserted into it but it stores the data by the keys...
    So QMap is no use in this...
    Can anyone advised me what would be the best to do this ?
    Thanks

  2. #2
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap model data

    I need to implement something like this...
    Qt Code:
    1. QVariant MsgStatsModel::data(const QModelIndex &index, int role) const
    2. {
    3.  
    4. QVariant ret;
    5.  
    6. if(!index.isValid()){
    7. std::cout <<"Invalid Index of data provided!"<< std::endl;
    8. return ret;
    9. }
    10.  
    11. int row = index.row();
    12. int col = index.column();
    13.  
    14. if(row >= 0 && row < rowCount()) {
    15. if(role == Qt::DisplayRole) {
    16. //get the OBJECT stored on "row"
    17. switch(col) {
    18. case 0 :
    19. ret = QVariant(/*HERE THE ID MUST BE RETURNED*/);
    20. break;
    21. case 1:
    22. ret = QVariant(/*HERE THE COUNT OF THE ID MUST BE RETURNED*/);;
    23. break;
    24. }
    25. }
    26. }
    27. return ret;
    28. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap model data

    Hm as I see it...the only chance to do this statistcs thing is using the QList of QMaps

  4. #4
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QMap model data

    Hi I tried to implement the model as I wrote above...
    But it somehow doesnt work and I dont know why
    Can anyone please tell me what Im doing wrong ?
    Or whats the best way to implement in Qt a statistics model that would store a count value(of received messages) under a key(id of concrete message) ?
    my codes are in attachement...
    ThAnks
    Attached Files Attached Files

Similar Threads

  1. Model - data
    By gyre in forum Newbie
    Replies: 1
    Last Post: 9th December 2007, 19:49
  2. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  3. Custom Model Class
    By mattjgalloway in forum Qt Programming
    Replies: 12
    Last Post: 4th June 2007, 17:30
  4. Informing a model its data has changed
    By saknopper in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 19:58
  5. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 17:28

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.