Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQueryModel headerData Qt::Vertical Display keep increasing the row numbers

QSqlQueryModel headerData Qt::Vertical Display keep increasing the row numbers

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.2k 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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    i SubClassed the QSqlQueryModel and i try to calculate the Vertical header display based on select query . the wierd thing here is that the headerData method keep calling itself and the number ofcource keep increasing . why ? isn't it called as many times as the rows displayed? this is my function

    @QVariant ListSqlModel::headerData(int section, Qt::Orientation orientation, int role) const
    {

    if(orientation == Qt::Vertical && role == Qt::DisplayRole)
    {
    
        int returnHeaderCount = iHeaderCount;
        QString h = QString::number(returnHeaderCount);
        LOG_MSG("RowCount:"+h.toStdString());
        iHeaderCount++;
        return returnHeaderCount;
    }
    

    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You cannot rely on the fact that headerData is only called once.

      If you have pagination, I would add an attribute to the model, holding the current start index (= offset from the start) of the result set (as passed to limit/offset in the query) and in headerData just add that offset to the section number. This way your return value is always the same.

      http://www.catb.org/~esr/faqs/smart-questions.html

      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