Results 1 to 5 of 5

Thread: QSqlTableModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QSqlTableModel

    Qt Code:
    1. model->insertRow(-1, QModelIndex());
    2. model->setData(model->index(model->rowCount()-1, 0), "somedata");
    To copy to clipboard, switch view to plain text mode 

    But it's better to do it this way:
    Qt Code:
    1. QSqlRecord rec = model->record();
    2. rec.setValue("name", "John Doe");
    3. rec.setValue("age", 18);
    4. model->insertRecord(-1, rec);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    273
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 1 Time in 1 Post

    Default Re: QSqlTableModel

    Hi wysota
    It works
    Thanks to open my mind! I am allways happy when i have the possibility to stude some examples
    For insert new Values:
    Qt Code:
    1. QString table = ui.tabelle_le->text();
    2. model->setTable(table);
    3. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    4. model->select();
    5.  
    6. QSqlRecord rec = model->record();
    7. ui.tableView->setModel(model);
    8. ui.tableView->show();
    9.  
    10. //I have auto increment at this table, so i dont have to give the new id
    11.  
    12. rec.setValue("status", "test");
    13. model->insertRecord(-1, rec);
    To copy to clipboard, switch view to plain text mode 

    For Update a Value it works now like this:
    Qt Code:
    1. QString table = ui.tabelle_le->text();
    2. model->setTable(table);
    3. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    4. model->select();
    5. ui.tableView->setModel(model);
    6. ui.tableView->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by raphaelf; 4th March 2006 at 13:12.
    Think DigitalGasoline

Similar Threads

  1. Trouble with "INSERT" by QSqlTableModel
    By AD in forum Qt Programming
    Replies: 12
    Last Post: 10th November 2008, 08:21
  2. QSqlTableModel slow even with manual submit
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2008, 20:40
  3. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 12:47
  4. Replies: 4
    Last Post: 9th May 2008, 17:02
  5. QSqlTableModel Help pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 26th January 2006, 07:58

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.