当我收到 QLineEdit::textEdited()
信号时,我能看到编辑之前的文本吗?我需要比较编辑前的文本和编辑后的文本。
textEdited()
信号只有一个参数,即新文本。调用 QLineEdit::text()
也会返回新文本。
现在我只能想到将旧文本保存在 QString 中,并在每次编辑时更新该 QString,但随后我需要考虑程序更改(通过 QLineEdit::setText( )
).
或者是否有另一种方法可以拦截文本更改(可能通过验证器),让我可以同时获取更改前和更改后的文本?最好仅用于用户更改(非程序化)。
最佳答案
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())
当然,我也只能这样想,但请注意,与 textEdited() 不同,textChanged() 甚至允许您根据文档捕获程序更改:
Unlike textChanged(), this signal is not emitted when the text is changed programmatically, for example, by calling setText().
关于c++ - 在 QLineEdit::textEdited() 内部进行编辑之前获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24039795/