PDA

View Full Version : problems editing rows in a QTableView



cyrfer
5th January 2010, 09:23
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!

wysota
5th January 2010, 09:39
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.

cyrfer
6th January 2010, 01:46
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.

Tavit
6th January 2010, 06:47
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.

wysota
6th January 2010, 08:34
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.