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 my short code:

        QModelIndex TheIndex = ui->tableView->selectionModel()->currentIndex();
        TheModel->setEditStrategy(QSqlTableModel::OnFieldChange);
        TheModel->setData(TheModel->index(TheIndex.row(),2), true, Qt::EditRole);
        TheModel->select();
        // TheModel->submitAll();
        TheDB.close();
    

    Thanks.



  • You r working with current index. How r u changing current index ? That may b the issue.



  • @dheerendra
    what I know is that the current index changes when I select an other row.
    I can upload my code in "mega.nz", but I don't know if it's allowed here.



  • If ur selecting next row it should work. U can upload the code there. Will check it.



  • @dheerendra
    I'm sorry for my late reply. But, I replaced this with a new strategy.
    Thank you any way.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.