Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] QTableView and QSqlQueryModel: Change number of rows first loaded from model.



  • I am currently creating a tool to preview data from SQL database tables. I have QTableView that shows the data, and run-time I connect a QSqlQueryModel based on user click in a list of table names. The data is fetched from a SQLite database.

    Simplified, this is how i populate the view:

    @
    QString query = query = "SELECT * FROM " % ui.lswPreviewTables->currentItem()->text();
    QSqlQueryModel currentDataModel->setQuery(query, currentDatabase);
    tableView->setModel(currentDataModel);
    tableView->show();
    @

    My quyestion is: Is there a way to reduce the number of rows initially loaded? I have read somewhere in the forums that this is 255 or 256 rows. For a click-and-hold function for preview, the loading is a bit too slow when columns exceeds 70.

    Thanks in advance.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Depending on your needs, you could simply add a LIMIT to your query

    Hope it helps



  • That was really clever, SGaist. I don't know why that did not cross my mind. I want the user to be able to scroll the QTableView to see more data. Maybe a solution is to remove LIMIT from the model's query as soon as the scrollbar value changes.

    Thank you for your help.


Log in to reply