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. QTableView field (related to other db table) does not get refreshed
Qt 6.11 is out! See what's new in the release blog

QTableView field (related to other db table) does not get refreshed

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 109 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.
  • P Offline
    P Offline
    Panoss
    wrote on last edited by Panoss
    #1

    The articlesTable (a QTableView) displays data from db table 'articles'.
    The field 'positions' is related to table 'positions'.
    The code:

    // Create the data model for articles:
     model = new QSqlRelationalTableModel();
     model->setEditStrategy(QSqlTableModel:: OnFieldChange);
     model->setTable("articles");
     model->select(); 
    
     // Remember the indexes of the columns:
     positionIdx = model->fieldIndex("position");
    
     // Set the relations to the database table 'positions':
     model->setRelation(positionIdx, QSqlRelation("positions", "id", "name"));
    
     // articlesTable is a QTableView, set it's model
     ui.articlesTable->setModel(model);
    
    The problem:
    -I add a new record in database table 'positions'
    -I call model->select()  (to refresh articlesTable)
    -the new record is not displayed in the combo box of field 'positions'
    
    I must close the form and reopen it in order for this field to display the new record.
    How can I fix this?
    
    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