I have created my own QListModel through deriving from QAbstractListModel.

MZ_NoteListModel.h
Qt Code:
  1. #ifndef MZ_NOTELISTMODEL
  2. #define MZ_NOTELISTMODEL
  3.  
  4.  
  5. #include <QAbstractListModel>
  6. #include <QObject>
  7.  
  8. class MZ_NoteListModel : public QAbstractListModel
  9. {
  10. public:
  11. MZ_NoteListModel(QObject *parent = NULL);
  12. QVariant headerData(int section, Qt::Orientation orientation, int role) const ;
  13. int rowCount ( const QModelIndex & parent = QModelIndex() ) const ;
  14. QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const ;
  15. Qt::ItemFlags flags ( const QModelIndex & index ) const ;
  16. bool setData ( const QModelIndex & index, const QMap<int, QVariant> & roles ) ;
  17. QMap<int, QVariant> itemData ( const QModelIndex & index ) const ;
  18.  
  19. private:
  20. };
  21.  
  22. #endif
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "mz_noteListModel.h"
  2. #include <QDebug>
  3.  
  4. MZ_NoteListModel::MZ_NoteListModel(QObject *parent) : QAbstractListModel(parent)
  5. {
  6.  
  7. }
  8.  
  9. QVariant MZ_NoteListModel::headerData(int section, Qt::Orientation orientation, int role) const
  10. {
  11. if (orientation == Qt::Horizontal)
  12. {
  13. if (role == Qt::DisplayRole)
  14. {
  15. return QString("Notes");
  16. }
  17. }
  18. return QVariant();
  19. }
  20.  
  21. int MZ_NoteListModel::rowCount ( const QModelIndex & parent ) const
  22. {
  23. return 3;
  24. }
  25.  
  26.  
  27. QVariant MZ_NoteListModel::data ( const QModelIndex & index, int role ) const
  28. {
  29. if(index.isValid())
  30. {
  31. switch(index.row())
  32. {
  33. case 0:
  34. return QString("0");
  35. break;
  36. case 1:
  37. return QString("1");
  38. break;
  39. case 2:
  40. return QString("2");
  41. break;
  42. default: return QVariant(); break;
  43. }
  44. }
  45. return QVariant();
  46. }
  47.  
  48. bool MZ_NoteListModel::setData ( const QModelIndex & index, const QMap<int, QVariant> & roles )
  49. {
  50. if( index.isValid() )
  51. {
  52. return true;
  53. }
  54. return false;
  55. }
  56.  
  57. Qt::ItemFlags MZ_NoteListModel::flags ( const QModelIndex & index ) const
  58. {
  59. if(index.isValid())
  60. {
  61. return Qt::ItemIsEditable;
  62. }
  63. return 0;
  64. }
  65.  
  66. QMap<int, QVariant> MZ_NoteListModel::itemData ( const QModelIndex & index ) const
  67. {
  68. QMap<int, QVariant> role;
  69. if(index.isValid())
  70. {
  71. role[index.row()] = Qt::DisplayRole;
  72. }
  73. return role;
  74. }
To copy to clipboard, switch view to plain text mode 

My Problem is, when I make a QListView and set the model to my MZ_NoteListModel, the View is only white. Nothing, no header, no rows, nothing!!

Qt Code:
  1. #include <iostream>
  2. #include <QListView>
  3. #include <QApplication>
  4.  
  5. #include "mz_noteListModel.h"
  6.  
  7. int main(int argc, char** argv)
  8. {
  9. QApplication q(argc, argv);
  10.  
  11. MZ_NoteListModel *noteModel = new MZ_NoteListModel();
  12. QListView noteView;
  13. noteView.setModel(noteModel);
  14. noteView.show();
  15.  
  16. return q.exec();
  17. }
To copy to clipboard, switch view to plain text mode 

Please, can anybody help me?

Thanks