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. How can i retrieve a qtableview from stored procedure?
Forum Updated to NodeBB v4.3 + New Features

How can i retrieve a qtableview from stored procedure?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 678 Views
  • 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.
  • N Offline
    N Offline
    nhokworm
    wrote on last edited by
    #1

    I created a stored procedure:
    //your code here

    CREATE PROCEDURE dbo.TableView
    AS
    SELECT * 
    FROM table
    GO
    

    When i call this sp on frontend what code i need to write to retrieve a qtableview?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      2 things:

      • A table view can't hold data, it needs a model: http://doc.qt.io/qt-5/model-view-programming.html
      • A stored procedure is likely a forward only query so you cannot use QSqlQueryModel out of the box

      You'll need to run the query manually and add the results into a model (QStandardItemModel?).
      To see how to prepare a query see the stored procedure section of http://doc.qt.io/qt-5/qsqlquery.html#approaches-to-binding-values

      here is some (horrible) code in which I download data from a stored procedure and populate a tree model with it, I hope it helps

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      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