2014-09-29 87 views

回答

5
QRegExp rx("regex"); 
QValidator *validator = new QRegExpValidator(rx, this); 

QLineEdit *edit = new QLineEdit(this); 
edit->setValidator(validator); 

凡正则表达式的字符串:

[a-zA-Z]+ 

对于数字:

[0-9]+ 
+0

@LionKing请出示你的代码,你应该包括QRegExp和QRegExpValidator写QRegExp RX(“[0 -9] +“);如果它没有帮助,那么显示你的代码 – Chernobyl 2014-09-29 12:31:05

+0

@LionKing它应该是QRegExp模式(“[a-zA-Z] +”);编译器不能转换你的代码。 – Chernobyl 2014-09-29 12:35:52

+1

@LionKing数字有'QIntValidator'和'QDoubleValidator'。使用正则表达式进行数字验证的开销很大。此外,还可能存在国际化问题。 – 2014-09-29 13:02:32