1. 程式人生 > >在QTavleView中新增QLineEdit(用正則表示式校驗輸入的IP地址)

在QTavleView中新增QLineEdit(用正則表示式校驗輸入的IP地址)

在QTableView中新增QLineEdit,並且該QLineEdit是需要填入IP地址,因此輸入的資料必須遵循IP地址的規則。這時可以使用QT中的委託。

委託的一篇文章http://blog.csdn.net/hello_world_lvlcoder/article/details/59478712

QLineEdit *editor = new QLineEdit(parent);

QRegExp rx("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$"); 

editor->setValidator(new QRegExpValidator(rx, parent));

editor->setInputMask("000.000.000.000;0");//必須加;0否則前面的正則表示式失效,;0”表示刪除時預設填充為0