SHARE
TWEET

qt4 to qt5 porting of roleNames code

a guest Nov 9th, 2013 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NotificationsModel::NotificationsModel(QObject *parent) :
  2. QAbstractListModel(parent)
  3. {
  4. QHash<int, QByteArray> roles = roleNames();
  5. roles[Qt::DisplayRole] = QByteArray("title");
  6. roles[ObjectRole] = QByteArray("object");
  7. roles[BodyRole] = QByteArray("body");
  8. roles[CountRole] = QByteArray("count");
  9. setRoleNames(roles);
  10. }
  11.  
  12. //roleNames needs to be reimplemented
  13.  
  14. //in .h
  15. public:
  16.     virtual QHash<int, QByteArray> roleNames() const;
  17. private:
  18.     QHash<int, QByteArray> _roles;
  19. //in .c
  20. NotificationsModel::NotificationsModel(QObject *parent) :
  21.     QAbstractListModel(parent)
  22. {
  23.     QHash<int, QByteArray> _roles = roleNames();
  24.     _roles[Qt::DisplayRole] = QByteArray("title");
  25.     _roles[ObjectRole] = QByteArray("object");
  26.     _roles[BodyRole] = QByteArray("body");
  27.     _roles[CountRole] = QByteArray("count");
  28. }
  29.  
  30. QHash<int, QByteArray> NotificationsModel::roleNames() const
  31. {
  32.     return _roles;
  33. }
  34.  
  35. //gets me
  36. watchletsmodel.cpp:18:24: error: prototype for 'QHash<int, QByteArray> sowatch::WatchletsModel::roleNames()' does not match any in class 'sowatch::WatchletsModel'
  37. watchletsmodel.h:26:36: error: candidate is: virtual QHash<int, QByteArray> sowatch::WatchletsModel::roleNames() const
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