这个例子中,是使用QLineEdit加入正则表达式来实现ip地址的输入功能的,不符合规范的数据将不能输入:

 

[cpp] view plain copy
 
 Qt中限制IP输入的正则表达式:Qt中限制IP输入的正则表达式:
  1. QRegExp regExpIP("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[\\.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])");  
  2. QRegExp regExpNetPort("((6553[0-5])|[655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])");  
  3. QRegExp regExpChannel("[0-5]");  
  4.   
  5. ui->lineEdit_locIP->setValidator(new QRegExpValidator(regExpIP,this));  
  6. ui->lineEdit_subNetMask->setValidator(new QRegExpValidator(regExpIP,this));  
  7. ui->lineEdit_GatewayIP->setValidator(new QRegExpValidator(regExpIP,this));  
  8. ui->lineEdit_serIP->setValidator(new QRegExpValidator(regExpIP,this));  
  9. ui->lineEdit_serPort->setValidator(new QRegExpValidator(regExpNetPort,this));  
  10. ui->lineEdit_rfChannel->setValidator(new QRegExpValidator(regExpChannel,this)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
  • 2022-02-22
  • 2021-05-25
猜你喜欢
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案