Results 1 to 1 of 1

Thread: How to update the selected row in QTableview using a button

  1. #1
    Join Date
    Dec 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to update the selected row in QTableview using a button

    Hi,

    I am using a QSqlTableModel for a SQlite database.
    The SQLite database contains a:
    - Table: "ThePer"
    - Columns: ID, Name, Work.

    Also, I have a Tableview to display the database's content, and a button to update the content of the selected row.
    When I click the button to update the 'Work' column of the selected row, thats work only the first time. And doesn't work when I want to update an other selected row.


    This is a short code of my MyExample.zip:

    Qt Code:
    1. QModelIndex TheIndex = ui->tableView->selectionModel()->currentIndex();
    2. TheModel->setEditStrategy(QSqlTableModel::OnFieldChange);
    3. TheModel->setData(TheModel->index(TheIndex.row(),2), true, Qt::EditRole);
    4. TheModel->select();
    5. // TheModel->submitAll();
    6. TheDB.close();
    To copy to clipboard, switch view to plain text mode 


    Thanks.
    Last edited by lmofallis; 3rd April 2017 at 18:08.

Similar Threads

  1. qtableview - selected row after add new row
    By stevocz in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2016, 10:27
  2. QTableView, selected row?
    By postb99 in forum Newbie
    Replies: 1
    Last Post: 25th February 2014, 14:57
  3. QTableView get selected row
    By raphaelf in forum Qt Programming
    Replies: 8
    Last Post: 12th July 2013, 03:35
  4. Replies: 6
    Last Post: 25th September 2012, 23:41
  5. How to get the selected row when click the button in it?
    By weixj2003ld in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2011, 10:00

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.