Results 1 to 7 of 7

Thread: QTableView and QSQLTableModel

Hybrid View

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

    Default Re: QTableView and QSQLTableModel

    Its not easy to bring this on text

    I try again:

    I am testing QSqlTableView class for update, delete and insert a new dataset (record) in a Table.

    My situation now:
    i am able to update a Table like this (really easy, i had just to change the EditStrategy ):
    Qt Code:
    1. QString table = ui.tabelle_le->text();
    2. model->setTable(table);
    3. //So kann man jeder Feld update: OnFiledChange
    4. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    5. model->select();
    6. ui.tableView->setModel(model);
    7. ui.tableView->show();
    To copy to clipboard, switch view to plain text mode 
    i am able too, to delete a dataset like this(very simple):
    Qt Code:
    1. .
    2. .
    3. model->removeRows(x,1);
    To copy to clipboard, switch view to plain text mode 
    What i need now, is to find a simple way, how to insert a new dataset over my tableView
    I now that i can use this:
    Qt Code:
    1. rec.setValue("status", "test");
    2. model->insertRecord(-1, rec);
    To copy to clipboard, switch view to plain text mode 
    So my problem is:
    1. I have 18 tables
    2. every table has between 2 and 23 columns.
    3. How to insert a new dataset over my TableView in a easy Way independent of which table is set as Modal?

    I hope i could explain better, if not i shoul lern more english
    Think DigitalGasoline

  2. #2
    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: QTableView and QSQLTableModel

    Just insert an empty row into your model using insertRow() or insertRecord() with an empty record and order the view to go into edit mode on the newly inserted row.

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

    Default Re: QTableView and QSQLTableModel

    Hi Wysota!
    finally i am able now to input a new rec
    I hope you mean like that:
    Qt Code:
    1. void MainWindow::insertNewRow()
    2. {
    3. QString table = ui.tabellen_cb->currentText();
    4. model->setTable(table);
    5. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    6. model->select();
    7.  
    8. ui.tableView->setModel(model);
    9. ui.tableView->show();
    10.  
    11. //Just insert an empty row into your model using insertRow() or insertRecord()
    12. //with an empty record
    13. QSqlRecord rec = model->record();
    14. model->insertRecord(-1, rec);
    15.  
    16. //and order the view to go into edit mode on the newly inserted row.
    17. model->setEditStrategy(QSqlTableModel::OnRowChange);
    18. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

Similar Threads

  1. Replies: 2
    Last Post: 6th January 2009, 20:55
  2. QSqlTableModel and QTableView selection problems
    By innerhippy in forum Qt Programming
    Replies: 5
    Last Post: 19th December 2008, 05:48
  3. QTableView, QSqlTableModel - data disappears
    By msh in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2008, 11:50
  4. QTableView and QSqlTableModel problem
    By Misenko in forum Qt Programming
    Replies: 5
    Last Post: 19th August 2008, 21:58
  5. QSqlTableModel and QTableView and sorting
    By JeanC in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2008, 13:22

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.