Results 1 to 2 of 2

Thread: QT Network htonl

  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QT Network htonl

    I have a data coming from a server on a TCP Connection and the data comes in network byte order.
    is there any specific class in Qt that performs this conversion or should i use the native ntohs() methods of linux.

    i tried using the native method call but that doesnot give any change!
    can anyone please enlighten me on this....

    Qt Code:
    1. struct{
    2. quint16 i;
    3. }
    4. tcp->read((char*)i,sizeof(i));
    5. ntohs(i);
    To copy to clipboard, switch view to plain text mode 

    i am working in QT4.2.2 Red Hat Linux
    Last edited by csvivek; 9th May 2008 at 16:11. Reason: updated contents

  2. #2
    Join Date
    Apr 2008
    Location
    Pavlodar, Kazakhstan
    Posts
    22
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT Network htonl

    When working with QTcpSocket I usually use this approach:
    Qt Code:
    1. quint16 i;
    2. QByteArray packet;
    3. QDataStream in(&packet, QIODevice::ReadOnly);
    4.  
    5. // This function sets the byte order of incoming data; network format is BigEndian,
    6. // while Intel format is LittleEndian
    7. in.setByteOrder(QDataStream::BigEndian);
    8. packet = socket->read(sizeof(i));
    9. in >> i;
    To copy to clipboard, switch view to plain text mode 
    I've learned this approach from "C++ GUI Programming with Qt 4", so I think it is the recommended one.

Similar Threads

  1. Checking network availability
    By fullmetalcoder in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2008, 19:23
  2. No network when Modem Emulator connect to a real device
    By tommy_tang in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 10th December 2007, 08:24
  3. Send QEvents over network?
    By Winni in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2007, 20:58
  4. qmake ignores network?
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2007, 09:29
  5. QSocket - signal for network wire disconnection
    By manivannan_1984 in forum Qt Programming
    Replies: 7
    Last Post: 5th September 2006, 13:52

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.