Results 1 to 5 of 5

Thread: QSqlTableModel and insertRecord()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlTableModel and insertRecord()

    What is the editStrategy() on the model?

    This code:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtSql>
    3. #include <QDebug>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication app(argc, argv);
    9.  
    10.  
    11. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    12. db.setDatabaseName(":memory:");
    13. db.open();
    14. QSqlQuery query;
    15. query.exec("CREATE TABLE test (a INTEGER, b VARCHAR(10))");
    16. query.exec("INSERT INTO test VALUES (1, 'One')");
    17. query.exec("INSERT INTO test VALUES (2, 'Two')");
    18. query.exec("INSERT INTO test VALUES (3, 'Three')");
    19.  
    20.  
    21. model.setTable("test");
    22. model.select();
    23.  
    24. // model.setEditStrategy(QSqlTableModel::OnRowChange);
    25. model.setEditStrategy(QSqlTableModel::OnManualSubmit);
    26.  
    27. qDebug() << "Starting with" << model.rowCount();
    28. for (int i = 0; i < 20; ++i) {
    29. QSqlRecord record = model.record();
    30. qDebug() << i << model.rowCount();
    31. model.insertRecord(-1, record);
    32. }
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 
    Works as expected with one value and not the other.

  2. #2
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel and insertRecord()

    Thanks for your reply. I think that I now know how to work with Model / View Framework.

Similar Threads

  1. Replies: 8
    Last Post: 30th March 2011, 20:06
  2. QSqlTableModel and LIKE
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2008, 08:45
  3. QSqlTableModel Help pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 7th March 2006, 19:40
  4. QSqlTableModel
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2006, 12:35
  5. QSqlTableModel Help pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 26th January 2006, 07:58

Tags for this Thread

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.