Results 1 to 2 of 2

Thread: How to send quint32 variable in server-client

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to send quint32 variable in server-client

    i am writing a server-client program. i am passing various messages between them. i am easily able to send qstream data type, but facing problem in sending quint32 data. my function for writing data is


    void comn::sendMAC()
    {
    if(tcpSocket->isOpen())
    {
    QString str2 = QVariant( calc_mac ).toString(); //calc_mac is quint32
    tcpSocket->write(QString(str2 + "\n").toUtf8());
    qDebug() << "Sending to server: " << calc_mac;
    clienttextEdit->append( "sending: " + str2);

    }
    }

    - with above function, i am converting quint32 into qstring & then sending. but i am again stuck, because at receiver side i want data as quint32 & not qstring.
    - there can be 2 solution for this:-
    - send data in quint32 form only.
    - or if sending in qstring, then convert back into quint32. but how??
    -- please help.THANX

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to send quint32 variable in server-client

    You listed two possible solutions; I am not sure what help you are expecting.

    Put the bytes of your quint32 you want to send, in the order you want to send them, into a QByteArray and then write it to the QTCPSocket.
    OR
    Modify the receiver to put the bytes of the string into a buffer (QByteArray) and convert to uint. Read the QByteArray docs to find number conversion functions.


    See also the same question here: http://www.qtcentre.org/threads/3188...able-in-socket
    Last edited by ChrisW67; 24th June 2010 at 01:52.

Similar Threads

  1. sending quint32 variable in socket
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 24th June 2010, 01:56
  2. Replies: 7
    Last Post: 7th June 2010, 14:13
  3. tcp QT server - .Net c# client
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2010, 22:15
  4. My client can't send data
    By hiuao in forum Qt Programming
    Replies: 10
    Last Post: 23rd February 2007, 09:32
  5. client-server how?
    By nongentesimus in forum Newbie
    Replies: 6
    Last Post: 28th November 2006, 09:25

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
  •  
Qt is a trademark of The Qt Company.