Results 1 to 6 of 6

Thread: Updating SQL Database from QTableView

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Updating SQL Database from QTableView

    I am trying to update an SQL Database from a QTableView. I can view the contents of my database in my QTableView as well as insert a row into the QTableView and have it appear in my Database via manual submit and clicking a button. However I have not been able to edit a cell in my QTableView and have the change appear in the Database. Can someone point me in the right direction?

  2. #2
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating SQL Database from QTableView

    I still haven't been able to figure this out. I've been looking at the Cache Table example as a go by and what I'm trying to do isn't any different than what's in the example.

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Updating SQL Database from QTableView

    Sounds like it could be your edit strategy setting.
    I have a model/view set on a sqlite database table with
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    If I double click in a view cell, make an edit, then hit return, the data change is saved to the database table.

  4. #4
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating SQL Database from QTableView

    I just noticed something when trying what you suggested, when a cell is already populated and I make a change then it works. When a cell is blank from adding a row and not setting the data yet it doesn't work. So I'll play with it some more. I'm guessing by adding a row with blank cells and not setting the data the TableView doesn't know how to handle the edit.

  5. #5
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating SQL Database from QTableView

    I figured it out. When adding rows (at least from my tests) you have to set data for all fields even if you initially want them blank to fill in later.

  6. #6
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Updating SQL Database from QTableView

    Great - glad you got it working. I never had the problem since my rows are always populated when created.

Similar Threads

  1. QTableView top row not updating
    By murrekatt in forum Newbie
    Replies: 4
    Last Post: 3rd March 2010, 14:50
  2. updating QTableView with new qsl columns
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 28th January 2009, 20:51
  3. Updating a data in QTableView question
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 6th June 2008, 11:45
  4. updating database with custom delegate
    By Shaitan in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2007, 10:34
  5. updating database
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2007, 05:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.