Results 1 to 9 of 9

Thread: QStandardItemModel changes to QSqlTableModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default QStandardItemModel changes to QSqlTableModel

    Hello i have a problem i looked a lot but did not find a exact solution. I have a
    QStandardItemModel to which i am adding data which is present in the QVectors which is retrieved from the data base and i set this data Model into the tableView.

    This is how i am displaying the data from a data base to QTableView
    Qt Code:
    1. model1 = new QStandardItemModel();
    2. for(int i=0;i< temptagidnames.count(); i++)
    3. {
    4. QStandardItem *item = new QStandardItem(temptagidnames.at(i));
    5. model1->setItem(i, 0, item);
    6. }
    7. model1->setHeaderData(0, Qt::Horizontal, tr("TAG ID"));
    8. model1->setHeaderData(1, Qt::Horizontal, tr("Description"));
    9. tableView->setModel(model1);
    10. tableView->setAlternatingRowColors(true);
    11. tableView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    To copy to clipboard, switch view to plain text mode 

    I wrote the below code to update the changes made in the QTableView into the sqlite db.

    Qt Code:
    1. model1 = new QStandardItemModel();
    2. QSqlTableModel *model1;
    3. model1 = new QSqlTableModel;
    4.  
    5. model1->setTable("tempchnames");
    6. model1->setEditStrategy(QSqlTableModel::OnFieldChange);
    7. tableView->setColumnHidden(0, true);
    8.  
    9. for(int i=0;i< temptagidnames.count(); i++)
    10. {
    11. QStandardItem *item = new QStandardItem(temptagidnames.at(i));
    12. model1->setItem(i, 0, item);
    13. }
    14.  
    15. model1->setHeaderData(0, Qt::Horizontal, tr("TAG ID"));
    16. model1->setHeaderData(1, Qt::Horizontal, tr("Description"));
    17.  
    18. tableView->setModel(model1);
    19. tableView->setAlternatingRowColors(true);
    20. tableView->setSizePolicy(QSizePolicy::Expanding,
    To copy to clipboard, switch view to plain text mode 

    But i get errors like, I am not able to know how i can link QStandardItemModel Model and QSqlTableModel so that the changes i make in the QTableView are reflected in the data base immediately.
    error C2371: 'model1' : redefinition; different basic types
    error C2039: 'setTable' : is not a member of 'QStandardItemModel'
    i am stuck with this problem past 2 days,.
    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStandardItemModel changes to QSqlTableModel

    You have to delete the first two lines of code

    Qt Code:
    1. model1 = new QStandardItemModel();
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. Replies: 8
    Last Post: 30th March 2011, 20:06
  2. using QStandardItemModel
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 6th March 2011, 09:13
  3. QAbstractItemModel, QStandardItemModel
    By homerun4711 in forum Newbie
    Replies: 2
    Last Post: 16th December 2010, 09:18
  4. QStandardItemModel Help
    By frenk_castle in forum Newbie
    Replies: 1
    Last Post: 16th January 2010, 17:54
  5. Print QStandardItemModel
    By Mrdata in forum Newbie
    Replies: 1
    Last Post: 4th July 2007, 23:14

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.