Results 1 to 5 of 5

Thread: problems editing rows in a QTableView

  1. #1
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default problems editing rows in a QTableView

    I am new to Qt and SQL, so please bear with me. I have been able to connect to a database and view it through the use of QSqlRelationalTableModel and QTableView. I am now trying to hook up code to a button for inserting a new row, or deleting a selected row. I have tested my SQL statements with the SQLite command line interpreter for both inserting and deleting. When I execute the QSqlQuery to do the same thing as what I typed on the command line, I see the wrong behavior. For example, when I want to "INSERT INTO...", not one row but 2 rows are inserted!

    The same problem exists when I go to delete a row, two rows are deleted. I've connected to the QTableView's clicked() signal, which passes a QModelIndex so that I can grab the index's row and perform a delete on that row. I hope I am correct when I say that I've noticed the rows are ORDERED BY SQLite's ROWID. So, I'm able to delete a specific ROWID based on the row index returned by the clicked() signal.

    Again, I've tested my SQL commands in the interpreter and they work great. When I use the Qt SQL code, extra inserts and deletes occur. Is this a bug?


    I would be open to using a different database implementation, but I don't know how to use those and I'm short on time. As a side note, how does one create a new database without using something like the SQLite command line tool? Can you write Qt code to create a new DB?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problems editing rows in a QTableView

    Most likely you have doubled connect() statements or one insertion/deletion is caused by your query and the second one by the model itself. Hard to verify that without seeing your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems editing rows in a QTableView

    I thought about that. I used breakpoints in the debugger to verify that my callback is hit just once. Is it possible there is a bug in the SQLite driver? Thanks for the suggestion.

  4. #4
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: problems editing rows in a QTableView

    Hi,
    We can trace the database driver using the qDebug staments in console output. Please put the staments line by line in Database driver creation.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problems editing rows in a QTableView

    Quote Originally Posted by cyrfer View Post
    I used breakpoints in the debugger to verify that my callback is hit just once.
    Please provide a minimal compilable example reproducing the problem.

    Is it possible there is a bug in the SQLite driver?
    It's very unlikely. People would have complaint about it years ago and in general issuing sql statements to sqlite works fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Problem with editing QTableView
    By TimoSan in forum Qt Programming
    Replies: 0
    Last Post: 23rd November 2009, 10:46
  2. Problems editing QTableWidgetItem
    By SCV in forum Qt Programming
    Replies: 0
    Last Post: 27th June 2009, 21:06
  3. QTableView 2 rows inside every row
    By skuda in forum Qt Programming
    Replies: 3
    Last Post: 22nd April 2009, 09:23
  4. QTableView, editing, validating input
    By jml in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 00:57
  5. Copying QTableView rows
    By derrickbj in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 00:00

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.