Results 1 to 14 of 14

Thread: submitAll() -> "no fields to update"

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: submitAll() -> "no fields to update"

    Hello

    I get such error (i.e., error in submitAll after insertRows) using Sqlite and Qt 4.7.1. Is this still the previously mentioned unresolved bug, or do I something wrong?

    The code below produces an ASSERT failure in the last row with the error message "No Fields to update". The two lines that are commented out are two options that I tried.

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
    2. db.setDatabaseName(QLatin1String("testdb.db"));
    3. Q_ASSERT(db.open());
    4. QSqlQuery sqlQuery(db);
    5. bool ok;
    6. // ok = sqlQuery.exec(QLatin1String("CREATE TABLE Table1 (Content, Identifier INTEGER PRIMARY KEY AUTOINCREMENT, Parent INTEGER NOT NULL, Details);"));
    7. ok = sqlQuery.exec(QLatin1String("CREATE TABLE Table1 (Content, Identifier INTEGER PRIMARY KEY AUTOINCREMENT, Parent, Details);"));
    8. // ok = sqlQuery.exec(QLatin1String("CREATE TABLE Table1 (Content, Identifier, Parent, Details);"));
    9. Q_ASSERT_X(ok, "CREATE TABLE sql statement", "Table1 likely already exists");
    10. ok = sqlQuery.exec(QLatin1String("INSERT INTO Table1(Content, Parent, Details) VALUES ('first item', 0, 'Details for first item');"));
    11. Q_ASSERT(ok);
    12.  
    13. QSqlTableModel* tableModel = new QSqlTableModel(this, db);
    14. tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    15. tableModel->setTable(QLatin1String("Table1"));
    16. tableModel->select();
    17. tableView->setModel(tableModel);
    18. tableView->resizeColumnsToContents();
    19.  
    20. ok = tableModel->insertRows(0, 1, QModelIndex());
    21. Q_ASSERT(ok);
    22.  
    23. ok = tableModel->submitAll();
    24. Q_ASSERT_X(ok, "submitAll", qPrintable(tableModel->lastError().text()));
    To copy to clipboard, switch view to plain text mode 
    Any help appreciated; either to correct my code or to find a work-around.

    Al_

    Edit:
    others have issues with removeRows ..., see http://www.qtcentre.org/threads/3876...ght=insertRows
    Last edited by Al_; 26th February 2011 at 15:47.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.