qtqt3

How does QTable behave for last edited cell?


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??


Solution

  • 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.