Results 1 to 4 of 4

Thread: Change database data in the QTabelView

  1. #1
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Change database data in the QTabelView

    I have shown the data in a QTabelView through the following codes:
    Qt Code:
    1. model->setTable("Person");
    2. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    3. model->select();
    4. model->removeColumn(0); // don't show the ID
    5. model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    6. model->setHeaderData(1, Qt::Horizontal, tr("Sex"));
    7. model->setHeaderData(2, Qt::Horizontal, tr("Age"));
    8. ui->tableView->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    But when I change the data in the tableview, the data in the table do not change. when I update the tableview, the data are the same as they were before changed.
    How can I change the data in a QSLite table, through the QTabeView.
    The help of Qt says that we can use
    Qt Code:
    1. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    To copy to clipboard, switch view to plain text mode 
    to change the data through the QTableView, but I failed.
    Who has the same problem and give me a hand??
    Thank you in advance!!

  2. #2
    Join Date
    Apr 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change database data in the QTabelView

    If You use OnManualSubmit you have to submitAll data.
    Use a QPushButton and connect the clicked signal to a custom slot, that call's:
    Qt Code:
    1. tableView->submitAll();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change database data in the QTabelView

    I have to what you said, but it didn't work.
    And even if I change the argument of
    Qt Code:
    1. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    To copy to clipboard, switch view to plain text mode 

    into
    Qt Code:
    1. QSqlTableModel::OnRowChange
    To copy to clipboard, switch view to plain text mode 
    it doesn't work either, where is wrong

  4. #4
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change database data in the QTabelView

    This is what I get from the console when I run the application:

    Starting H:/QTprojects/testsqlite2/debug/testsqlite2.exe...
    QSqlQuery::value: not positioned on a valid record
    QSqlQuery::value: not positioned on a valid record
    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.

    H:/QTprojects/testsqlite2/debug/testsqlite2.exe exited with code 0

    Is there something wrong with my application??

Similar Threads

  1. Problem while inserting the data into database
    By sudheer168 in forum Qt Programming
    Replies: 2
    Last Post: 13th December 2008, 12:22
  2. Replies: 2
    Last Post: 8th August 2008, 01:54
  3. Replies: 15
    Last Post: 27th May 2008, 01:46
  4. Replies: 5
    Last Post: 8th April 2008, 23:10
  5. How to get data from .mdb database?
    By whoops.slo in forum Newbie
    Replies: 3
    Last Post: 26th January 2006, 21:27

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.