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. Qt SqlTableModel Inserting Row Problem
QtWS25 Last Chance

Qt SqlTableModel Inserting Row Problem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 327 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.
  • Q Offline
    Q Offline
    Qt Single programmer
    wrote on last edited by Qt Single programmer
    #1

    Hello to everybody
    i have a problem with inserting records by "QSqlTableModel" so i use the below scenario to explain my problem.

    i have table in database with auto generation primary key(for example student table with id primary key auto generation) and i use "QSqltableModel" in my program. so when i want add single row to model and enter all fields for it, inserting method insert record in database nicely and show it to view correctly too.("selectRow(int row)" method update record correctly).
    but when I enter all fields except Id(auto generation primary key) in this case inserting record in database work correctly but it doesn't update view correctly and show empty row. i trace Qt code and notice that Qt use "primaryValues(int row)" method to generate "whereStatement" base user input. (for example in this case it generate "ID IS NULL" wherestatement). since id of records generate by database, selectRow() return nothing and record in view doesn't update so show empty row.
    this problem raise because Qt doesn't support returning values in inserting records.
    i modify some Qt SourceCode methods like selectRow() and solve it but i want to know is there any way to solve this problem without re-implementing Qt sourceCode?

    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