⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

abandoning/reverting changes in a QDialog

  • Hi all -

    I'm writing an app that uses a QDialog to edit a row in a QAbstractItemModel. I just realized that if I make changes to some fields, then hit cancel, my changes are retained. This is probably a side effect of working directly in the model, but I can't have this. Is there a standard way of handling this?

  • Lifetime Qt Champion


    You can use QDataWidgetMapper with the submitPolicy set to ManualSubmit. That way you fully control when the changes are sent to your model.

  • Oh, that's a thing of beauty.

        QDataWidgetMapper *m_mapper;
        if (buttonPushed == QMessageBox::Save)
            // we specified manual submit policy in c'tor,
            // so we need to call submit() here.

    Thanks, SGaist.

Log in to reply