[Qt-interest] Problem removng rows in QSqlRelationalTableModel

Petric Frank pfrank at gmx.de
Tue Jun 30 02:59:32 CEST 2009


Hello,

whenever i try to delete a row in a table it says it have been done, but it 
isn't (i checked the database contents.
At submit time i see at application output (i'm using QtCreator) the 
message "QSqlQuery::value: not positioned on a valid record".

If i remove the relation definition everything works well.

I know there is a note in the spec of QSqlRelationalTableModel that the 
primary key may not form a relation to antother table.

Is there any hint for me to circimvent this (other than deriving my own 
QSqlTableModel) ?

Environment: QT 4.5.2 (tested on Linux and Windows with MySQL Database).

Two tables:
- Table1: index (int), id (int) - both together form the primary key
- Table2: id (int), value (varchar) - id is primary key

Sample code:
------------------- cut -------------------
QSqlRelationalTableModel *model = new QSqlRelationalTableModel (this);
model->setEditStrategy (QSqlTableModel::OnManualSubmit);
model->serTable ("Table1");
model->setRelation (1, "Table2", "id", "value");
ui.tableView->setModel (model);
model->select ();

... later in the code ...

if (!model->removeRow (1))      // row dores exist - 
  QMessageBox::warning (this, "SQL error", model->lastError ().text ());

... later in the code ...

if (!model->submitAll ())
  QMessageBox::warning (this, "SQL error", model->lastError ().text ());
------------------ cut -------------------

None of the warning message boxes do pop up - so removeRow and submitAll 
telling "everythng well" which is not the fact.

regards
  Petric



More information about the Qt-interest-old mailing list