Qt-interest Archive, March 2007
qt ready fn to extract ip address from a qstring
Message 1 in thread
hello there
is there a qt function to extract an ip address v4 (aaa.bbb.ccc.ddd)
from a long QString
(basically reading line by line a text file) ?
thank you
nass
--
[ signature omitted ]
Message 2 in thread
QHostAddress anAddress(QString("107.98.1.1"));
QString aStringAddress;
aStringAddress = anAddress.toString();
From your question, it was not clear which you wanted, long to
string or string to long. I just gave you both.
Michael
On Mar 26, 2007, at 6:54 AM, )\((@sS <athanasios.silis@xxxxxxxxx> wrote:
> hello there
> is there a qt function to extract an ip address v4 (aaa.bbb.ccc.ddd)
> from a long QString
> (basically reading line by line a text file) ?
>
> thank you
> nass
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 3 in thread
)\(@sS wrote:
> hello there
> is there a qt function to extract an ip address v4 (aaa.bbb.ccc.ddd)
> from a long QString
> (basically reading line by line a text file) ?
>
You could always use a QRegExp something on the order of
"(\\d{1,3}\\.\\d{1,3}\\.\\d{1.3}\\.\\d{1,3})"
Didn't try the regular expression, so you might have to play with it,
but that should be close.
Darrik Mazey
> thank you
> nass
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 4 in thread
If he asked a question that has your answer, the a better answer
would be:
QString ipStr("192.168.1.1");
QStringList octets;
octets = ipStr.split(".");
QList<QString>::iterator octet = octets.begin();
while (octet != octets.end())
{
// a this point, first time through, octet contains "192"
octet++;
}
On Mar 26, 2007, at 2:52 PM, darrik mazey wrote:
> )\(@sS wrote:
>> hello there
>> is there a qt function to extract an ip address v4 (aaa.bbb.ccc.ddd)
>> from a long QString
>> (basically reading line by line a text file) ?
>>
> You could always use a QRegExp something on the order of "(\\d{1,3}\
> \.\\d{1,3}\\.\\d{1.3}\\.\\d{1,3})"
>
> Didn't try the regular expression, so you might have to play with
> it, but that should be close.
>
> Darrik Mazey
>
>> thank you
>> nass
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
>> with "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 5 in thread
Michael Simpson wrote:
> If he asked a question that has your answer, the a better answer would
> be:
>
> QString ipStr("192.168.1.1");
> QStringList octets;
>
> octets = ipStr.split(".");
>
> QList<QString>::iterator octet = octets.begin();
> while (octet != octets.end())
> {
> // a this point, first time through, octet contains "192"
> octet++;
> }
>
From the OP, he's parsing a text file line by line, trying to extract
ip addressses. Thus it's not going to be QString ipStr("192.168.1.1")
but rather QString someLine("there will be an ip address like
192.168.1.1 somewhere in this line, probably because it comes from a
log"). I don't think split() is what the OP is after.
Darrik Mazey
--
[ signature omitted ]
Message 6 in thread
Nass,
There seems to be some confusion about exactly what you want; specifically,
what else will be in the QString besides the ip address? If the ip address
will be by itself, you want to use QHostAddress. If the ip address will be
mixed in with other text that has no predictable form, you probably want a
regular expression.
Tom
On 3/26/07, )(@sS <athanasios.silis@xxxxxxxxx> wrote:
>
> hello there
> is there a qt function to extract an ip address v4 (aaa.bbb.ccc.ddd)
> from a long QString
> (basically reading line by line a text file) ?
>
> thank you
> nass
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>