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 don’t refresh with QSqlTableModel
Forum Updated to NodeBB v4.3 + New Features

QTableView don’t refresh with QSqlTableModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.7k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kiko007
    wrote on last edited by
    #1

    I’m using QSqlTableModel with QTableView and I have a problem when try insert datas. QTableView don’t refresh. I test insertRow() with setData(), setRecord(), insertRecord(), submitAll(), and nothing.
    I try with QSqlQuery::exec and return true, but de rowCount() return 0.
    I have 4 tables in my DB:

    @QSqlDtabase db;
    QSqlTableModel model(0, db);
    QTableView table;
    table.setModel(&model);
    model.setTableName("student");
    model.setEditStrategy(QSqlTableModel::OnManualSubmit)ñ
    model.select();
    model.insertRecord(dataStudentRecord)
    model.submitAll();
    @

    and nothing....somebody Help me. Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You should try to provide code that will compile and demonstrates the problem. There's no QSqlTablemodel::insertRecord() that accepts a single value for example.

      Here are some questions that might help you isolate the problem:

      • Is the database connection is successfully opened? Did you check?
      • Does a table called "student" exist in the database?
      • Is dataStudentRecord a QSqlRecord that matches this model?
      • QSqlTableModel::insertRow(), QSqlTableModel::setData(), QSqlTableModel::setRecord() and QSqlTableModel::submitAll() all return a value, did you check it?
      • Are you sure your record is actually insertable and inserted? Does it violate database check or referential integrity constraints?
      • When it fails, did you check the result of QSqlTableModel::lastError()?

      Updating the table other than through the model, i.e. by executing a QSqlQuery separately, will not update the view or model unless you reset the model.

      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