Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-1734

QTableView shows empty rows when QSqlTableModel::setTable() is called multiple times

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P3: Somewhat important
    • Some future release
    • 4.3.3
    • SQL Support
    • None

    Description

      QTableView shows empty rows when QSqlTableModel::setTable() is first called before the model is set on the view, and then called after the model is set on the view.

      This can be reproduced on Linux using a MYSQL driver with the following example:

      #include <QtGui>
      #include <QtSql>
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
      
          QTableView table;
      
          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("");
          db.setUserName("");
          db.setPassword("");
          db.setDatabaseName("");
      
          db.open();
      
          QSqlQuery query;
          query.exec("DROP TABLE IF EXISTS task_201361_foo;");
          query.exec("DROP TABLE IF EXISTS task_201361_bar;");
          query.exec("CREATE TABLE task_201361_foo (id integer PRIMARY KEY, entry text)");
          query.exec("CREATE TABLE task_201361_bar (id integer PRIMARY KEY, entry text)");
      
          for (int i = 0; i < 3; ++i) {
              query.exec(QString("INSERT INTO task_201361_foo (id, entry) VALUES (%0, 'entry %0')").arg(i));
              query.exec(QString("INSERT INTO task_201361_bar (id, entry) VALUES (%0, 'entry %0')").arg(i));
          }
      
          QSqlTableModel *model = new QSqlTableModel(&table);
          model->setTable("task_201361_foo");
          model->select();
      
          table.setModel(model);
      
          model->setTable("task_201361_bar");
          model->select();
      
          table.show();
      
          return app.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mgoddard Michael Goddard (closed Nokia identity) (Inactive)
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes