c++ - 在 QLineEdit::textEdited() 内部进行编辑之前获取文本

标签 c++ qt qtgui qlineedit qvalidator

当我收到 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/

相关文章:

c++ - 将 C++ 头文件转换为 Python

c++ - 添加 resources.rc 文件信息项目

c++ - b2Draw子类成员函数未调用

c++ - C++ Windows/Mac/iOS 中的西类牙字符

c++ - 在 OpenGL 中,(如何)我可以在两个深度缓冲区之间进行深度测试?

c++ - 对 MasterController::StaticMetaObject 的 undefined reference

c++ - QTcpSocket "leaks"内存

c++ - 如何在主窗口中显示文本?

python - 如何使用Python在Maya中设置目录?目前使用 PyQt4 但欢迎任何建议

c++ - 如何使用自动添加的 Qt 元素