Results 1 to 4 of 4

Thread: Missing rows in QSqlTableModel

  1. #1
    Join Date
    Oct 2016
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Missing rows in QSqlTableModel

    Hi,
    i'm loading a table in a sqlite db file through QSqlTableModel, but while the original table has 2847 records, the view shows only 2755. QSqlTableModel::lastError() does not report any issue.

    How can I debug the problem? This is the code I'm using:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2.  
    3. db.setDatabaseName(currentDatabase.absoluteFilePath());
    4.  
    5. if (!db.open()) {
    6. QMessageBox::critical(this, qApp->tr("Error opening database"),
    7. "Cannot connect to database.\n" + db.lastError().text(), QMessageBox::Cancel);
    8. return;
    9. }
    10.  
    11. tableModel = new QSqlTableModel(this, db);
    12. ui->tableView->setModel(tableModel);
    13. tableModel->setTable("my_table");
    14. tableModel->select();
    15. ui->tableView->show();
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,376
    Thanks
    246
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Missing rows in QSqlTableModel

    Have you verified that an external tool such as DB Browser for SQLite returns the correct count?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2016
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Missing rows in QSqlTableModel

    Quote Originally Posted by d_stranz View Post
    Have you verified that an external tool such as DB Browser for SQLite returns the correct count?
    Yes, already verified

    Screenshot_20200324_204349.png

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,376
    Thanks
    246
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Missing rows in QSqlTableModel

    You don't show the context of the code you posted. If it all lives in a single method, then I wonder if it has anything to do with your "db" variable going out of scope at the end of the method? Otherwise, your code seems to be OK.

    What does QSqlTableModel::selectStatement() return? Anything suspicious there?
    Last edited by d_stranz; 24th March 2020 at 22:12.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QSqlTableModel doesn't delete the rows
    By AlexxanderX in forum Newbie
    Replies: 1
    Last Post: 17th September 2014, 04:10
  2. Replies: 3
    Last Post: 17th July 2013, 06:07
  3. Replies: 0
    Last Post: 11th October 2012, 11:25
  4. Sum of rows in QSqlTableModel
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2010, 21:05
  5. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 13:47

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.