QSqlQueryModel rolenames

John Plummer jcpconecomp at gmail.com
Tue Feb 14 21:47:42 GMT 2023


     In Qt5/Qt6 the column names of the SQL query in an QSqlQueryModel 
can be accessed using 'record' .  For example the column names can be 
added as roleNames with the following:

QHash<int, QByteArray> roleNames() const
     {
         QHash<int, QByteArray> roles;
         for (int i = 0; i < record().count(); i ++) {
             roles.insert(Qt::UserRole + i + 1, 
record().fieldName(i).toUtf8());
         }
         roles.insert(Qt::DisplayRole, "display" );
         return roles;
     }

     Is the 'record' (or column names) available in PyQt6?

     By the way, I am fairly new with PyQt.  The implementation is 
impressive.  Thanks.




More information about the PyQt mailing list