<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Solved]QLineEdit - Validator doesn&#x27;t allow to input IP Address]]></title><description><![CDATA[<p dir="auto">I've got this code:<br />
@<br />
ServerIpAddressEdit-&gt;setInputMask(QString("000.000.000.000; "));<br />
ServerIpAddressEdit-&gt;setValidator( new QRegExpValidator( QRegExp("[0-255].[0-255].[0-255].[0-255]" , Qt::CaseInsensitive), this));<br />
ServerIpPortEdit-&gt;setValidator(new QIntValidator(1, 65535, this));<br />
@</p>
<p dir="auto">QRegExpValidator doesn't allow me to input digits into ServerIpAddressEdit(QLineEdit), why?? When I comment this line, everything is okay, but it doesn't validate...</p>
]]></description><link>https://forum.qt.io/topic/5619/solved-qlineedit-validator-doesn-t-allow-to-input-ip-address</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Nov 2026 22:25:30 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/5619.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 08 May 2011 13:06:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved]QLineEdit - Validator doesn&#x27;t allow to input IP Address on Sun, 08 May 2011 14:10:25 GMT]]></title><description><![CDATA[<p dir="auto">I don't think you can mix masks and validators for this problem (after 5 long minutes of google search....).</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qstring">@<bdi>QString</bdi></a> Octet = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";<br />
lineEdit-&gt;setValidator(new QRegExpValidator(<br />
QRegExp("^" + Octet + "\." + Octet + "\." + Octet + "\." + Octet + "$"), this));@</p>
<p dir="auto">This will work, stoled it from "here":<a href="http://lists.trolltech.com/qt-interest/2004-05/thread00085-0.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://lists.trolltech.com/qt-interest/2004-05/thread00085-0.html</a>.</p>
<p dir="auto">edit:<br />
Or you could do something like "this":<a href="http://www.qtcentre.org/threads/6228-Ip-Address-Validation:" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.qtcentre.org/threads/6228-Ip-Address-Validation:</a></p>
<p dir="auto">@    class IP4Validator : public QValidator {<br />
public:<br />
IP4Validator(QObject *parent=0) : QValidator(parent){}<br />
void fixup(QString &amp;input) const {}<br />
State validate(QString &amp;input, int &amp;pos) const {<br />
if(input.isEmpty()) return Acceptable;<br />
QStringList slist = input.split(".");<br />
int s = slist.size();<br />
if(s&gt;4) return Invalid;<br />
bool emptyGroup = false;<br />
for(int i=0;i&lt;s;i++){<br />
bool ok;<br />
if(slist[i].isEmpty()){<br />
emptyGroup = true;<br />
continue;<br />
}<br />
int val = slist[i].toInt(&amp;ok);<br />
if(!ok || val&lt;0 || val&gt;255) return Invalid;<br />
}<br />
if(s&lt;4 || emptyGroup) return Intermediate;<br />
return Acceptable;<br />
}<br />
};@</p>
]]></description><link>https://forum.qt.io/post/86931</link><guid isPermaLink="true">https://forum.qt.io/post/86931</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 08 May 2011 14:10:25 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved]QLineEdit - Validator doesn&#x27;t allow to input IP Address on Sun, 08 May 2011 13:44:18 GMT]]></title><description><![CDATA[<p dir="auto">In RegExp: \. or even \\. instead just "."<br />
Also [0-255] means different, you may need \d{1,3}, to match 1-3 digits</p>
]]></description><link>https://forum.qt.io/post/86929</link><guid isPermaLink="true">https://forum.qt.io/post/86929</guid><dc:creator><![CDATA[yshurik]]></dc:creator><pubDate>Sun, 08 May 2011 13:44:18 GMT</pubDate></item></channel></rss>