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?

    Qt 4.7.0



  • Have you declare b as a QString before using it here?

    I've tried and everything works fine:
    @QHostAddress a;
    a = QHostAddress( "127.0.0.1" );
    QString b;
    b = a.toString();
    qDebug() << b;@

    outputs:

    bq. "127.0.0.1"


  • Moderators

    Interesting. Especially because Qt documentation is using "127.0.0.1" as examples for the constructor as well as the toString method.


  • Moderators

    Hi Peppy,

    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.

    Best regards
    koahnig



  • 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()));@

    output:

    bq. Host Addess: 8.24.22.123



  • adaitabehera with 0 before number it takes as octal number but displays as decimal


  • Moderators

    [quote author="adaitabehera" date="1364035749"]Can any body explain this:[/quote]
    "Yes":http://en.wikipedia.org/wiki/Octal



  • In fact the octal representation should be "0010.0030.0026.0123" which is in decimal "8.24.22.83". 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.