How to set Input Mask and QValidator to a QLineEdit at a time in Qt?

后端 未结 5 1397
一生所求
一生所求 2020-12-31 21:14

I want a line edit which accepts an ip address. If I give input mask as:

ui->lineEdit->setInputMask(\"000.000.000.000\");

It is accep

5条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 21:44

    In accordance to Arun Kumar K S's answer:

    If myIP.setAddress() was successfull, you can write the ip back to the line edit as a formatted string:

    ui->lineEdit->setText(myIP->toString());
    

    Consequently, you don't neccessarily need to set a mask (nor a validator or regex).

    Note setAddress() writes/overwrites your myIP also if it fails to read the ip. Thus, calling toString() in this case results in an empty string.

提交回复
热议问题