thePoet
4th July 2009, 17:22
I have a QSqlRelationalTableModel that references a simple lookup table containing a primary key named id of type text (string uuid) and a name field of type text. When I insert into the QSqlRelationalTableModel, it only uses the most recently created id in the lookup table.
When I insert a new item in the lookup table, and then attempt to add a new item in the QSqlRelationalTableModel, the new item regularly fails on setData on the column with the relationship. It doesn't always fail, but it usually does. If it fails using that key, it will always fail with that key. If it doesn't, it will always succeed with that key.
if( !_itemModel->setData(_itemModel->index(0,4), _locationUuid) )
{
QMessageBox::critical(0, "set data 4 failed",
_itemModel->lastError().text(), QMessageBox::Cancel);
}
I can't figure out what the cause is. The _itemModel->lastError() doesn't return any text. If I look at the table with a third party tool, the item was properly inserted into the lookup table. Am I supposed to do something to the model to tell it that the data it references was updated?
Also, the lookup table is being managed by a QSqlTableModel. The insert looks like this:
if( !_locationModel->insertRow(0) )
{
QMessageBox::critical(0, "insert failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
if( !_locationModel->setData(_locationModel->index(0,0), _locationUuid) )
{
QMessageBox::critical(0, "set data 1 failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
if( !_locationModel->setData(_locationModel->index(0,1),location) )
{
QMessageBox::critical(0, "set data 2 failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
if( !_locationModel->submitAll() )
{
QMessageBox::critical(0, "submit failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
When I insert a new item in the lookup table, and then attempt to add a new item in the QSqlRelationalTableModel, the new item regularly fails on setData on the column with the relationship. It doesn't always fail, but it usually does. If it fails using that key, it will always fail with that key. If it doesn't, it will always succeed with that key.
if( !_itemModel->setData(_itemModel->index(0,4), _locationUuid) )
{
QMessageBox::critical(0, "set data 4 failed",
_itemModel->lastError().text(), QMessageBox::Cancel);
}
I can't figure out what the cause is. The _itemModel->lastError() doesn't return any text. If I look at the table with a third party tool, the item was properly inserted into the lookup table. Am I supposed to do something to the model to tell it that the data it references was updated?
Also, the lookup table is being managed by a QSqlTableModel. The insert looks like this:
if( !_locationModel->insertRow(0) )
{
QMessageBox::critical(0, "insert failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
if( !_locationModel->setData(_locationModel->index(0,0), _locationUuid) )
{
QMessageBox::critical(0, "set data 1 failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
if( !_locationModel->setData(_locationModel->index(0,1),location) )
{
QMessageBox::critical(0, "set data 2 failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}
if( !_locationModel->submitAll() )
{
QMessageBox::critical(0, "submit failed",
_locationModel->lastError().text(), QMessageBox::Cancel);
}