[Qt-interest] QSqlTableModel doesn't save new entries, editing works fine

Sven Grunewaldt strayer at olle-orks.org
Thu Feb 5 01:39:59 CET 2009


Am 02.02.2009 14:09, schrieb Sven Grunewaldt:
> Am 02.02.2009 00:00, schrieb Tony Rietwyk:
>    
>> Svan wrote:
>>
>>
>>      
>>> Hi,
>>>
>>> I use a QSqlTableModel to display a simple SQLite database.
>>> When I edit
>>> an entry everything works correctly, but as soon as I want to add an
>>> entry it doesn't "submit" the changes.
>>> The row is added to the tableView and can be edited, but the
>>> beforeInsert Slot won't be executed and there is no change to
>>> the database.
>>>
>>> I'd appreciate any help, I'm at a total loss...
>>>
>>> Here is the part of the code I use:
>>> <code sniped>
>>>
>>>        
>> Hi Sven,
>>
>> What is the EditStrategy setting?
>>
>> I found two problems when using IBASE - maybe similar things happen for
>> SQLITE:
>>
>> - OnRowChange was not committing when selecting a new row until the new row
>> was put into edit mode.
>>
>> - OnManualSubmit with my own commits still failed because the internal edit
>> query was not being cleared when the manual transaction was committed on the
>> database object. This only manifested when the same query was repeatedly
>> executed - so insert, commit, edit, commit, insert was OK, but insert,
>> commit, insert failed with "system error prevents execution" on the second
>> insert.
>>
>> Having wasted many weeks on trying to get model based stuff working, I had
>> to abandon them and do the DB grids myself! :O(
>>
>> Regards,
>>
>> Tony
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>      
> I didn't change the EditStrategy, but using the Debug Dialog I found
> that it uses "OnRowChange".
> Sadly I have no idea how to debug this problem... :/
>
> Regards,
> Sven Grunewaldt
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>    
I tried it again with the QMYSQL driver, but still no chance.

I now connect my beforeInsert slots manually because I saw two errors 
under linux that it couldn't find the beforeInsert Signals on 
QSqlTableModel:
     connect(schuleModel, SIGNAL(beforeInsert(QSqlRecord&)), this, 
SLOT(schuleModel_beforeInsert(QSqlRecord&)));
     connect(betriebModel, SIGNAL(beforeInsert(QSqlRecord&)), this, 
SLOT(betriebModel_beforeInsert(QSqlRecord&)));

When I debug the application now it actually goes into the 
*Model_beforeInsert() slots, but nothing is inserted in the database...



More information about the Qt-interest-old mailing list