Results 1 to 10 of 10

Thread: Count the number of rows in a QTableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Location
    Bato, Leyte, Philippines
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11
    Thanked 2 Times in 2 Posts

    Default Re: Count the number of rows in a QTableView

    I'm posting these codes to try to help you solve your problem. It works on my simple database project.

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(":genes:");

    QSqlTableModel *empmodel = new QSqlTableModel();
    empmodel->setTable("person");
    empmodel->select(); // populate records

    QString s;
    s= s.setNum(empmodel->rowCount()); // returns the number of rows

    this->setWindowTitle(s); // display it

    empmodel->setHeaderData(0, Qt::Horizontal, tr("ID"));
    empmodel->setHeaderData(1, Qt::Horizontal, tr("NAME"));
    empmodel->setHeaderData(2, Qt::Horizontal, tr("ADDRESS"));

    QTableView *empview = new QTableView();
    empview->setModel(empmodel);
    empview->resize(QSize::QSize(800,250));
    empview->resizeColumnsToContents();

    empview->show();

  2. #2
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    4
    Thanked 5 Times in 4 Posts

    Default Re: Count the number of rows in a QTableView

    The best way to count rows:
    tableView.verticalHeader()->count();
    I don't remember if that count() returns the total or only visibles row number-check it by yourself.

  3. The following 2 users say thank you to MasterBLB for this useful post:

    Ashkan_s (11th October 2012), lxman (31st July 2011)

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 15:29
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. Replies: 6
    Last Post: 5th March 2006, 21:05
  5. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 06:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.