Question

When I edit a cell of QTable inside QDialog and press 'ok' button of QDialog, the cell's value is nothing (if it was nothing before edit). So, in the slot for OkButton (i.e. OkButton->clicked()), I access value of every cell in the QTable. However, the last edited cell is not yet filled. Strange!

Note, if I click somewhere else within QTable before pressing OkButton, it works fine, that is, I can then see the last edited cell's value with QTable->text(row, col). Could someone please help me in understanding what is missing here that results in this behavior?

Another interesting behavior: In the slot for OkButton, since, I don't find a value, I call QMessageBox::information(). During debugging, when I say 'next' (in gdb) on this statement, the valueChanged() signal is emitted (I am catching it and printing). I don't understand why is this signal so delayed; why did QTable did not record the changed value earlier??

Was it helpful?

Solution 2

One of the possible solution is to trigger endEdit() somehow. The method that I employed is to have following code from the handler/slot of OkButton.

mTable->setEnabled(false);  // wil trigger endEdit()
mTable->setEnabled(true);
// Access mTable's cells now
QString cell_content = mTable->text(i, j);

This code did solve the issue.

OTHER TIPS

I don't have a qt3 available, but I had a similar problem with QTableView in Qt 4.6.

You might have to call the function endEdit(row,col,true,false):

void QTable::endEdit ( int row, int col, bool accept, bool replace ) [virtual protected]

This function is called when in-place editing of the cell at row, col is requested to stop. If the cell is not being edited or accept is FALSE the function returns and the cell's contents are left unchanged.

If accept is TRUE the content of the editor must be transferred to the relevant cell. If replace is TRUE the current content of this cell should be replaced by the content of the editor (this means removing the current QTableItem of the cell and creating a new one for the cell). Otherwise (if possible) the content of the editor should just be set to the existing QTableItem of this cell.

I had to call commitData() in my case and this seems to do the same job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top