QHostAddress mysterious issue - hidden ip address...
I have this code:
a = QHostAddress("127.0.0.1");
b = a.toString();
// b is null ("")
Why is b (QString) empty?
Have you declare b as a QString before using it here?
I've tried and everything works fine:
a = QHostAddress( "127.0.0.1" );
b = a.toString();
qDebug() << b;@
Interesting. Especially because Qt documentation is using "127.0.0.1" as examples for the constructor as well as the toString method.
you probably did not forget to declare b, but left it out in your shortened example.
I have tried it with Qt 4.7.0 and MSVC installation on Win7 64 bit. In the debugger the string b shows "127.0.0.1".
So, the problem could be with the way you are checking the content of your string (debugger?). The compiler or OS could be other possibilities, but not very likely.
Ehm...no I didn't forget and also this IP was just an example...
[quote author="Peppy" date="1304870048"]Ehm...no I didn't forget and also this IP was just an example...[/quote]
Then show your complete code please, we cannot guess what you are doing wrong, and you have proven in a couple of threads that you've screwed up some C++ basics from time to time.
Can any body explain this:
@qDebug("Host Addess: %s", qPrintable(QHostAddress("010.030.026.123").toString()));@
bq. Host Addess: 184.108.40.206
adaitabehera with 0 before number it takes as octal number but displays as decimal
[quote author="adaitabehera" date="1364035749"]Can any body explain this:[/quote]
In fact the octal representation should be "0010.0030.0026.0123" which is in decimal "220.127.116.11". You can see only the first 3 octets are treated as octal because they are preceded with 0. How can a Host address be a combination of both octal and decimal? I think validation should include a length check (number of digits) in each octet before deciding it as octal, hexadecimal or decimal.
I came across this problem because my application accepts the IPV4 address from a line edit which has an input mask "000.000.000.000;-". If the address entered is "10-.30-.26-.123", then it works fine.
forgot to put inside code:
@“000.000.000.000;-“. If the address entered is “10-.30-.26-.123”@
why you have "-" chars in adress? if it means any digit you will have problem because there is no 30x or 26x in IP adresses, max is 255...
And I am not really sure what your problem is, can you describe it better?
And about this:
[quote author="adaitabehera" date="1364039601"]How can a Host address be a combination of both octal and decimal? [/quote]
That's simple, each number is translated to binary octet so it doesn't matter if it was put in as decimal, octal or hexadecimal number.