[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: QSqlQueryModel rolenames
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2023-02-26 14:13:23
Message-ID: ac724331ae9fd5f2fe7951626125591d () riverbankcomputing ! com
[Download RAW message or body]
On 14/02/2023 21:47, John Plummer wrote:
> 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?
Yes. Run...
>>> from PyQt6.QtSql import QSqlQueryModel
>>> help(QSqlQueryModel.record)
Phil
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic