This looks like exactly what I'm after, thanks!

I have one more question, though. Imagine that in addiction to those QLineEdits there are QPlainTextEdits as well. The parameters of "focusChanged()" are two QWidgets - how to call "undo()" on a QWidget? This is perhaps more general question C++ question but maybe Qt provides some ways about calling dynamically resolved methods. I'm asking because, for instance, Objetive C has this "respondsToSelector:" method which when returns YES, one can safely "call" a method of an object.

Or do I have to first "qobject_cast" a QWidget to QPlainTextEdit, and if unsuccessful then cast it to QLineEdit, ..?