Unsolved How To Change data (setData) in EditableModel child on QSqlQueryModel ?
-
@Taz742
Hi
Its a bit unclear what actual error is.
It does save new data to database but the view is not showing it ?
Or which part is not working for you ? -
Hi,
To add to @mrjj, the implementation of
setFirstName
looks suspicious. You seem to want to use positional placeholders while your query isn't written for that. -
@mrjj Yes, it saves new data in database but form shows old numbers
-
Ok, maybe you need to use the
http://doc.qt.io/qt-5/qabstractitemmodel.html#rowsAboutToBeRemoved
or some other function that fits the action you do to the data.Currently, you just change the database behind its back
so I guess what is wrong is that it cannot know that. :) -
@mrjj
It does not have setQuery(); -
QAbstractItemModel is the lowest base class of QSqlQueryModel.
-
-
I solved my problem.
QSqlQuery query; query.prepare("SELECT * FROM VALUTA"); query.exec(); ui->tableWidget->setColumnCount(3); ui->tableWidget->setRowCount(8); ui->tableWidget->setHorizontalHeaderLabels(QStringList() << "იდ" << "სახელი" << "კურსი"); ui->tableWidget->verticalHeader()->hide(); int i = 0; while(query.next()){ int j = 0; while(j < 3){ QTableWidgetItem* itm = new QTableWidgetItem(query.value(j).toString()); ui->tableWidget->setItem(i,j,itm); if(j == 0){ itm->setFlags(itm->flags() ^ Qt::ItemIsEditable); // **DISABLE EDIT** } j++; } i++; }
But the concrete problem has not been reached.
I write as resolved? -
@Taz742
If you still have the view issue then leave it open :) -
@mrjj
Yes, I will leave open. I think This topical theme. -
Hi,
Did you forget to emit dataChanged() signal after value updated?
This signal is must if you need to reflect the changes on UI. -
Hi. @RajeeshRaveendran
YES, I've seen this signal.
But UI->, update, when it changes, model-> setData doing nothing. -
@Taz742
Did u try to call
emit dataChanged()
in setData ? -
Hi Taz,
I did not get you. Let me explain a little more. Simply you should modify your model class to
bool EditAbleModel::setData(const QModelIndex &index, const QVariant &value, int /* role */)
{
/// update the data to database/internal data storage
emit dataChanged(); /// So that UI (QML) know the change occurred in background and query the new value by calling data() method to update UI.
}QVariant EditAbleModel::data(const QModelIndex &index, int role)
{
/// return your data as per custom db.
} -
@RajeeshRaveendran
Now I'm busy with something else and definitely I'll see into your answer.
thank for reply, and sorry english :))