Get text prior to edit from inside QLineEdit::textEdited()

1.8k views Asked by At

When I receive a QLineEdit::textEdited() signal, can I see what the text was prior to the edit? I need to compare the text as it was prior to the edit and the text after the edit.

The textEdited() signal has only one argument, which is the new text. Calling QLineEdit::text() also returns the new text.

Right now I can only think of is holding the old text in a QString, and updating that QString each time there is an edit, but then I need to account for programmatic changes (made via QLineEdit::setText()).

Or is there another way to intercept a text change (via validators perhaps) that would allow me to get the text prior to change and after change simultaneously? Preferably for user-changes only (non programmatic).

1

There are 1 answers

0
László Papp On

Right now I can only think of is holding the old text in a QString, and updating that QString each time there is an edit, but then I need to account for programmatic changes (made via QLineEdit::setText())

Granted, I can also only think of that way, but please note that unlike textEdited(), textChanged() would allow you to even catch the programmatic changes as per documentation:

Unlike textChanged(), this signal is not emitted when the text is changed programmatically, for example, by calling setText().