Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Convert Qt4.8 to Qt5.3 Project - QAbstractItemModel
QtWS25 Last Chance

Convert Qt4.8 to Qt5.3 Project - QAbstractItemModel

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 1.3k Views
  • 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.
  • FerdlF Offline
    FerdlF Offline
    Ferdl
    wrote on last edited by
    #1

    Hi,

    I'm using sqlite database and generate some table models for qml. This is working fine with qt4.8.
    No i have converted the qt4 project to qt5.3 and the

    void setRoleNames(const QHash<int, QByteArray> & roleNames)
    

    is not longer available.

    How is the best way to use new "roleNames()" function?

    // current qt4.8
    void database_model::generate_role_names()
    {
        QHash<int, QByteArray> role_names;
        for(int i = 0; i < record().count(); ++i)
        {
            role_names[Qt::UserRole + i + 1] = record().fieldName(i).toLatin1(); // obsolete Qt5 .toAscii()
        }
        setRoleNames(role_names); // obsolete Qt5    
    }
    

    Any ideas?

    Thank you

    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi,
      the docu says you should use the virtual function
      QHash<int, QByteArray> QAbstractItemModel::roleNames() const
      instead.
      -Michael.

      1 Reply Last reply
      0
      • FerdlF Offline
        FerdlF Offline
        Ferdl
        wrote on last edited by Ferdl
        #3

        Hi,

        i tried this and it seems to work correct...

        QHash<int, QByteArray> database_model::roleNames() const
        {
            QHash<int, QByteArray> role_names;
            for(int i = 0; i < record().count(); ++i)
            {
                role_names[Qt::UserRole + i + 1] = record().fieldName(i).toLatin1();
            }
            return role_names;
        }
        
            protected:
                QHash<int, QByteArray> roleNames() const;
        

        Any ideas or comments or any better solution?

        Thanks
        Ferdl

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          AFAIK, that's the correct way to do it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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