QSqlRelationalTableModel does not update



  • Hi, i am try to do an application with the Relational Table Model. I have two tables linked with one foreign key. Like this:

    ingredientes = new QSqlRelationalTableModel(this);
    ingredientes->setTable("RecetaProductos");
    ingredientes->setRelation(2, QSqlRelation("Productos", "id", "producto"));
    ingredientes->setFilter("receta_id = " + QString::number(model->data(model->index(0,0)).toInt()));
    ingredientes->select();

    The table RecetaProductos has 3 columns (receta_id, cantidad, producto_id)
    and other table Productos has 2 columns (id, nombre)

    Then i set the item delegate and model to the TableView

    ui->tableView_2->setItemDelegate(new QSqlRelationalDelegate(ui->tableView_2));
    ui->tableView_2->setModel(ingredientes);

    When i run the application i can see the table with the values of foreign key good, but when i try to edit a field i have and sql error, with this message

    QSqlError("1", "Unable to execute statement", "no such column: RecetaProductos.nombre")

    The QSql is trying to add a column that not exist, the column's name is from the foreign key and not the column of the table RecetaProductos, producto_id.

    How can i change this? Any people knows how do?

    Thanks!!



  • I can solved. The problem is: The table RecetaProductos does not have a index key, i add one column with name id, and mark as index and then, the application runs well.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.