QValidator.State TypeError

Ognyan Moore ognyan.moore at gmail.com
Wed Jun 14 16:19:27 BST 2023


Hi Phil,

When implementing my own subclass of QValidator, I get a "TypeError:
invalid result from Validator.validate()" error followed by a segfault on
macOS for the following code:

Example:


from PyQt6 import QtCore, QtGui, QtWidgets
import sys

class Validator(QtGui.QValidator):

    def validate(self, index_, pos):
        return QtGui.QValidator.State.Acceptable

if __name__ == "__main__":
    qApp = QtWidgets.QApplication(sys.argv)

    lineEdit = QtWidgets.QLineEdit()
    validator = Validator()
    lineEdit.setValidator(validator)
    lineEdit.show()
    qApp.exec()

Running this file generates a QLineEdit, but the moment you edit the
contents and have the widget lose focus the following error is emitted:

TypeError: invalid result from Validator.validate()
zsh: abort      python problem.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230614/c3452f21/attachment.htm>


More information about the PyQt mailing list