Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    3
    1275
    Loading More Posts
    • 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.
    • A
      asjafjell last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

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

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • A
          asjafjell last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post