QTableView commit data in code
-
I have a model based QTableView (using a QSqlTableModel) that has a manualsubmit policy.
No custom delegates or proxy models are used, just plain text editors are shown.
In code, the user clicks a button to save the data.
The problem is that if the user was typing something and didn't focus out of the current text, the tableview is not posting/submitting data (which is probably a good idea in general, but not what I need).
Can I somehow force the table view to post whatever is being edited, so I can then safely call submitAll on my model? -
Can someone please confirm that this is a "feature" of the QTableView (not being able to programmatically post what the user is editing), and I'm not missing something very obvious here?
-
Have look at "this reply":http://developer.qt.nokia.com/forums/viewreply/27159/ in another thread. We once ran into the same problem and solved it that way.
-
I'm afraid your comment in that post
Be aware that this will work with your combo boxes, but not with default generated line edits or the like!
is what messes it up for me....I'm just trying to use a QTableView in a straightforward manner for once (no delegates or proxies, with a couple of text fields) but with no luck
-
Meanwhile, my solution is something like (inside my manual save function)
@
QModelIndex ndx = ui->tableView->currentIndex();
if (ndx.isValid()) {
ui->tableView->setCurrentIndex( tbl->index(ndx.row(), 0));
ui->tableView->setCurrentIndex( tbl->index(ndx.row(), 1));
}
@
which only works if there are at least 2 columns, but at least it works. -
Ok... if I understand it correctly though, it can only work with subclassing?
-
You are talking about QTableView's endEdit() function?
Isn't that a protected function (so I need to subclass QTableView)? -
I'm sorry for insisting, but I don't understand something.
You are talking about a function that contains
@
void AnyClass::endEdit()
{
QModelIndex index = myTblVw->currentIndex();
myTblVw->currentChanged( index, index );
}
@
How do I get access to the auto-generated text edit of the QTableView, so I can wire it to this slot?
Also, isn't currentChanged protected too? -
I must be missing something very obvious here, because it's not working for me.
Inside my Qt class that owns the QTableView (say it's a variable named myTblVw) , I can't call
myTblVw->currentChanged(...) from my save() slot because it's a protected method.So you are saying I should create another class deriving from anything, and write a function like in the previous posts? How does that class get access to the QTableView? Even if I were to pass a pointer to myTblVw, it still won't be able to call the protected method.
How is this going to work without subclassing?