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. Inserting row into QSqlQueryModel trough QDataWidgetMapper
Forum Updated to NodeBB v4.3 + New Features

Inserting row into QSqlQueryModel trough QDataWidgetMapper

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 3.1k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    Gehaktbal
    wrote on last edited by
    #1

    Hello,

    I have subclassed a QSqlQueryModel and implemented the setData() and flags() function.
    I also implemented the insertRow() function to insert a blanc row in the database (append).
    After that i created a widget that uses the model and a qdatawidgetmapper. With this combination it is possible to edit EXISTING rows.

    Now the problems start when i want to insert a new row. In this case i must create the new row at the start of the widget so i can set the mapper to it. But if the user happens to CANCEL the dialog then i have a blanc row in my database. That can't be right.

    Now my guess is that a standard tablemodel will first cache the insert and submits the change to the database when "submit" on the datamapper is called.

    What is the best way to deal with this. I must use the qsqlquerymodel beceause my database has a lot of tables that cant be mapped with a standard relationaltablemodel. How should i insert and delete rows and prevent (caching?) having bogus data in the database.

    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