Results 1 to 3 of 3

Thread: [solved] QHostAddress::toSring() backwards?

  1. #1
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Question [solved] QHostAddress::toSring() backwards?

    This is odd, to me at least.

    I haver an integer that I convert to an IPv4 address using QHostAddress and setAddress(). (I pull the integers from /proc/net/tcp on Linux).

    Yet when I use toString() I get the IP address backwards by octet. For examples: "1.0.0.127" and "21.1.168.192"
    This is not what the docs say I should get (127.0.0.1 and 192.168.1.21, respectively) . Anyone else see this, and of so, how does one (simply) go about getting it output correctly? I could, I suppose, use split() and reverse the list order. But *ugh*, that'd be a hack plain and simple (though that could be said f using QHostAddress to convert an int to an IP address in dotted notation )
    Last edited by ucntcme; 27th November 2007 at 23:58. Reason: solved
    --
    The Real Bill

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QHostAddress::toSring() backwards?

    You probably have a little-endian machine and you should pass the number in network order (or vice-versa), but you are probably passing the number in host order. Try using htonl() and passing the result to setAddress().

  3. The following user says thank you to wysota for this useful post:

    ucntcme (27th November 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: QHostAddress::toSring() backwards?

    Ah thanks, that did it.

    Looking back at the docs for setAddress, it says for the ip6Addr entry to set high-order byte first, but nothing for ip4Addr. Methinks they should copy that over.

    funny how a totally unexpected result can really toss your wits out the window.
    --
    The Real Bill

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.