Results 1 to 3 of 3

Thread: Update changes in QTableView to sqlite data base

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

    Default Update changes in QTableView to sqlite data base

    Hello every one, i am working on a project where i display some data from sqlite database in a QTableView widget.. I am having a small problem, wanted to know how i can make QTableView editable and save the changes i make on the QTableView into the sqlite data base.. right now i am doing this i retrieve the data from Sqlite db and display it in the QTableView but i am not able to figure out how i can make it editable and save those changes into the sqilte db..
    This is what i am doing to display the data from the sqlite db into QTableView now,
    Qt Code:
    1. QSqlQuery sqpre("select Channel_Name,TagId,ChannelIndexPosi from tempchnames");
    2. if(sqpre.exec())
    3. {
    4. if (sqpre.first())
    5. {
    6. do
    7. {
    8. temperaturechnames.push_back(sqpre.value(0).toString());
    9. temptagidnames.push_back(sqpre.value(1).toString());
    10. indexCount.push_back(sqpre.value(2).toString());
    11. } while(sqpre.next());
    12. }
    13. }
    14.  
    15. model1 = new QStandardItemModel();
    16.  
    17. model2 = new QStandardItemModel();
    18.  
    19. for(int i=0;i< temptagidnames.count(); i++)
    20. {
    21. QStandardItem *item = new QStandardItem(temptagidnames.at(i));
    22. model1->setItem(i, 0, item);
    23. }
    24.  
    25. for(int j=0;j< temperaturechnames.count(); j++)
    26. {
    27. QStandardItem *item2 = new QStandardItem(temperaturechnames.at(j));
    28. model1->setItem(j, 1, item2);
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 


    Thank you

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

    Default Re: Update changes in QTableView to sqlite data base

    Hello some one pls suggest me on how i should go about doing this.. I am stuck not finding what i am looking for in google also..

    thank you

  3. #3
    Join Date
    Jun 2006
    Posts
    64
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Update changes in QTableView to sqlite data base

    nagabathula,

    Try using QSqlTableModel instead of a QSqlQuery. I just went through the same process and found that was the trick to be able to edit the data.

    B1.

Similar Threads

  1. Help with QT, SQLite, Update Statement
    By chetu1984 in forum Newbie
    Replies: 3
    Last Post: 17th March 2011, 23:24
  2. Replies: 4
    Last Post: 19th December 2010, 07:15
  3. Replies: 0
    Last Post: 21st April 2010, 17:25
  4. QTable - Data Base Problem
    By esq in forum Qt Tools
    Replies: 9
    Last Post: 28th May 2007, 00:08
  5. program for working with Data Base(i need it)
    By banakil in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 23: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.