<span style="font-size:24px;">正则表达式验证器
class QRegExpValidator : public QValidator
{
Q_OBJECT
Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp NOTIFY regExpChanged)
public:
explicit QRegExpValidator(QObject *parent = 0);
explicit QRegExpValidator(const QRegExp& rx, QObject *parent = 0);
~QRegExpValidator();
virtual QValidator::State validate(QString& input, int& pos) const;
void setRegExp(const QRegExp& rx);
const QRegExp& regExp() const { return r; }
Q_SIGNALS:
void regExpChanged(const QRegExp& regExp);
private:
Q_DISABLE_COPY(QRegExpValidator)
QRegExp r;
};</span>
<span style="font-size:24px;">QRegExpValidator *validator;
QLineEdit *lineedit;
QRegExp regexp("[0-9]{1,8}");
validator = new QRegExpValidator(regexp,this);
lineedit->setValidator(validator);//设置1-8位,允许出现0-9</span>