Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有什么方便的方法可以QChar通过某个 Qt 小部件输入一个字符?使用QLineEdit需要转换QString并QChar做一些验证?任何字符验证器?
QChar
QLineEdit
QString
您应该使用 QLineEdit::setMaxLength() 或使用 QLineEdit::setValidator() 设置验证器;
QRegExpValidator rv = new QRegExpValidator(QRegExp("^.$")); lineEdit->setValidator(rv);
您可以使用 maxLength 属性将输入限制为一个字符:
lineEdit->setMaxLength(1);
对于除此之外的验证,请实现您自己的QValidator。