python 2.7 - How to make IP validation for QtGui.QInputDialog.GetText() -


i writing code in pyside has button "change ip". when button clicked dialog box appears has text box. want validation on text box accept ip address.

i using code:

qtgui.qinputdialog.gettext(self, "title", "enter ip: ") 

afair, qinputdialog.gettext not support on-the-fly validation, if willing roll own dialog, use qregexpvalidator

1.look needed regex on internets (here, instance). see looks

^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ ip4

  1. create qregexp object, this:

rx = qregexp("regular_expression_string_from_step_1")

3.create qregexpvalidator instance , pass rx object it's constructor, this:

my_validator = qregexpvalidator(rx)  
  1. call my_line_edit.setvalidator(my_validator)

that's it, my_line_edit should refuse entry of non-valid ip adresses. if don't want go way, use python's own re moodule post-factum validation using regex step 1.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -