Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. SetRoleNames in Qt 5.0.1
Qt 6.11 is out! See what's new in the release blog

SetRoleNames in Qt 5.0.1

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 8.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    razario
    wrote on last edited by
    #1

    I try to use some code...
    @
    ListModel::ListModel(ListItem* prototype, QObject *parent) :
    QAbstractListModel(parent), m_prototype(prototype)
    {
    setRoleNames(m_prototype->roleNames());
    }
    @
    but QAbstractListModel don't contains function setRoleNames in Qt 5.0.1 libraryes, why and how to fix. I need to use some model from c++ and show it in QML

    [Please wrap code in @ tags -- mlong]

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      The problem is that ListModel is intended for simple lists without roles. You just have to use a more appropriate model that supports roles such as QStandardItemModel. Just look at this for a full example on how to use role names with C++:
      http://www.developer.nokia.com/Community/Wiki/Using_QStandardItemModel_in_QML

      1 Reply Last reply
      0
      • R Offline
        R Offline
        razario
        wrote on last edited by
        #3

        QStandardItemModel not contains method setRoleNames too. In example http://www.developer.nokia.com/Community/Wiki/Using_QStandardItemModel_in_QML i download file.
        @
        RoleItemModel::RoleItemModel(const QHash<int, QByteArray> &roleNames)
        {
        setRoleNames(roleNames);
        }
        @
        when compile i have error:
        C3861: setRoleNames identificator not found

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on last edited by
          #4

          Just read the example I sent you. It shows you exactly how to assign role names to a model.

          Quote:
          "There is no magic in RoleItemModel - it merely calls QAbstractItemModel::setRoleNames, which happens to be a protected member of QAbstractItemModel."

          1 Reply Last reply
          0
          • R Offline
            R Offline
            razario
            wrote on last edited by
            #5

            http://www.picshare.ru/view/1253145/
            QtCreator intellisanse show that.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jens
              wrote on last edited by
              #6

              razario. That is a protected member. You cannot call it unless you subclass the model.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                razario
                wrote on last edited by
                #7

                if it's protected I herit QAbstractItemModel and I try to use it in child class:
                this-> ...
                but it's not contains it.
                I open qstandarditemmodel.h and that's NOT contains this methodб сlass inherits.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  razario
                  wrote on last edited by
                  #8

                  Decided no more setRoleNames in Qt 5 methods. I need to override roleNames

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sam_dev
                    wrote on last edited by
                    #9

                    I have tried following the above comments but still I'm not getting the desired results, I'm not able to replace setRoleNames() with roleNames().

                    Can someone give an example or a code snippet which will show how we can port setRoleNames() API in Qt5 by overriding roleNames() API?

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved