How to edit cell row in costume model which inherits from QSqlTableModel ?
Unsolved
QML and Qt Quick
-
I want to edit a cell row but I am confused how to do it exactly here is my code:
usermodel.cpp:
bool UserModel::setData(const QModelIndex &index, const QVariant &value, int role){ if (index.isValid() && role == Qt::EditRole){ return QSqlTableModel::setData(index,value, role); } return false; }
profile.qml:
TextField { id: phone text: "8989341" } TextField { id: address text: "London" } ListView { id: view currentIndex: 0 delegate: Text { text: model.name } model: UserModel { id: user_model } } Button { id: save_btn text: "save" background: Rectangle { border.color: "silver" border.width: 2 radius: 10 } onClicked: { user_model.setData(user_model.index(1, 2), address.text) user_model.setData(user_model.index(2, 3), phone.text) } }
table schema:
users(u_id int primary key, name varchar, address varchar, phone int)
The above code does not save the edited data.