Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Auto Update Model in QWidgetMapper
hadi_m last edited by hadi_m
I use QWidgetMapper with a few QlineEdit for editing data in model. when user edit fields in QLineEdit the new data will placed in the model when the enter key( or changing the focus) is pressed. I want to change this behavior so I need the data within the model change on the fly. I mean that data in model change as soon as possible user enter any key without waiting for enter key or changing widget focus.
Is there any way to accomplish this kind of behavior?
This is not supported by QDataWidgetMapper, you have to write it by your own.
JonB last edited by JonB
I do this on a widget mapper for a whole bunch of
QSpinBoxes. I connect to
QSpinBox::valueChangedand the slot calls
QDataWidgetMapper::submit()to update the model immediately. It works a treat :)
Presumably you can do the same against
QLineEdit::textEdited. Note that there is a potential little wriggle. If you're not careful, you change the model, it then changes the widget, and then that re-raises the "changed" signal and you get stuck forever. My slot reads the current value from the model and exits if the value passed to the slot is the same as that retrieved from the model. I also use
Qt::QueuedConnectionto prevent the slot causing changes while still within the original signal call, which was a problem. These may be because I am using
QSpinBoxes, may not apply when using
QLineEdit::textEdited(which is a different signal from
QLineEdit::textChangedwhich will be emitted when you change the value in the model programmatically and it reflects back to the widget).