Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlRelationalTableModel does not update
QtWS25 Last Chance

QSqlRelationalTableModel does not update

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 872 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sebastian Oldani
    wrote on last edited by
    #1

    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!!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sebastian Oldani
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      3
      • J Offline
        J Offline
        jobusch
        wrote on last edited by
        #3

        This worked for me, too! Thanks a lot! How did you find out? If this is still happening to people like me, this seems to be a bug that is long time around, is it not?

        Using SQLITE and PySide6 by the way.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved