Qt-interest Archive, May 2008
Data not written to SQLite db using QDataWidgetMapper an QSqlTableModel
Message 1 in thread
To write data to the DB I use this piece of code:
these are declared inside the QMachine class:
QSqlRelationalTableModel SqlTblModel;
QSqlRelationalDelegate *SqlDelegate;
QDataWidgetMapper Map;
void QMachine::OnPshBtnSubmitClicked(void)
{
int ix = Map.currentIndex();
bool zRet = Map.submit();
if(zRet == false)
QMessageBox::critical(this, tr("Map Submit Error!"),
tr(SqlTblModel.lastError().text()));
else
{
zRet = SqlTblModel.submitAll();
if(zRet == true)
{
Map.setCurrentIndex(ix);
QMessageBox::information(this, tr("SqlTblModel Submit
Success!"), tr("Your Update Was Submitted to the Database."));
}
else
QMessageBox::critical(this, tr("Submit Error!"),
tr(SqlTblModel.lastError().text()));
}
}
//-----------------------------------------------------------------------------
this row:
QMessageBox::critical(this, tr("Submit Error!"),
tr(SqlTblModel.lastError().text()));
produce this error:
constraint failed Unable to fetch row.
Any idea about the error and the way to correct it?
begin:vcard
begin:vcard
fn:Massimo Manca
n:Manca;Massimo
org:Micron Engineering di Massimo Manca
adr:;;via della Ferriera, 48;Pordenone;PN;33170;ITALIA
email;internet:massimo.manca@xxxxxxxxxxxxxxxxxxxx
tel;work:+39 0434 1856131
tel;fax:+39 0434 1851032 / 178 273 3543
tel;cell:+39 349 4504979
url:http://www.micronengineering.it
version:2.1
end:vcard
Message 2 in thread
Massimo Manca wrote:
> To write data to the DB I use this piece of code:
>
> these are declared inside the QMachine class:
>
> QSqlRelationalTableModel SqlTblModel;
> QSqlRelationalDelegate *SqlDelegate;
> QDataWidgetMapper Map;
>
>
>
> void QMachine::OnPshBtnSubmitClicked(void)
> {
> int ix = Map.currentIndex();
> bool zRet = Map.submit();
>
> if(zRet == false)
> QMessageBox::critical(this, tr("Map Submit Error!"),
> tr(SqlTblModel.lastError().text()));
> else
> {
> zRet = SqlTblModel.submitAll();
> if(zRet == true)
> {
> Map.setCurrentIndex(ix);
> QMessageBox::information(this, tr("SqlTblModel Submit
> Success!"), tr("Your Update Was Submitted to the Database."));
> }
> else
> QMessageBox::critical(this, tr("Submit Error!"),
> tr(SqlTblModel.lastError().text()));
> }
> }
> //-----------------------------------------------------------------------------
>
>
>
> this row:
> QMessageBox::critical(this, tr("Submit Error!"),
> tr(SqlTblModel.lastError().text()));
> produce this error:
> constraint failed Unable to fetch row.
>
> Any idea about the error and the way to correct it?
>
It looks like there's a constraint on one of your table columns, and
that an update/insert is failing to execute. I'd have a look at your
column definitions, and then which data you're trying to insert/update
in it.
--
[ signature omitted ]
Message 3 in thread
Massimo Manca wrote:
>
> > It looks like there's a constraint on one of your table columns,
> and
>
> > that an update/insert is failing to execute. I'd have a look at
> your
>
> > column definitions, and then which data you're trying to
>
> > insert/update in it.
>
>
> I have this problem in every form where I use a QSqlQueryModel
> (because data come from more then 1 table) and QDataWidgetMapper. I
> read that QSqlQueryModel is read only so I suppose that raise some
> errors. Is there any way to make QSqlQueryModel read/write?
> >
>
>
You should possibly look at QSqlRelationalTableModel then I think if you
want editability on a dataset with foreign keys.
QSqlQueryModel/QSqlTableModel is not geared for multiple tables, but
rather more towards single table/single result set scenarios.
--
[ signature omitted ]