TextInput with mask for IP



  • I am trying to create a TextInput for IP Address, and i need to control the ranges(0-255).

    this is what tried:

    @
    TextInput
    {
    id: myIpEdit
    anchors.fill: parent
    cursorVisible: true
    focus: true

            validator: IntValidator{bottom: 0; top: 255;}
    
            inputMask: "000.000.000.000;0"
            
            selectByMouse: true
    

    }
    @

    but it did'nt work, so i tried to use regular expration:
    @
    TextInput
    {
    id: myIpEdit
    anchors.fill: parent
    cursorVisible: true
    focus: true

            validator: RegExpValidator{regExp: /^(([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))\.){3}([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))$/}
            inputMask: "000.000.000.000;0"
            
            selectByMouse: true
    

    }
    @

    This enable to control the range(upper limit: 255), but also prevent inserting of zeros to the text.

    how can I create this IP TextInput correctly?



  • I believe the input mask should be:
    @
    inputMask: "000.000.000.000;_"
    @

    see this documentation: "InputMask":http://qt-project.org/doc/qt-5/qlineedit.html#inputMask-prop



  • I take that back, I misread the doc... that's just the character holder.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.