Results 1 to 2 of 2

Thread: QByteArray with network data

  1. #1
    Join Date
    Sep 2006
    Thanked 3 Times in 2 Posts
    Qt products
    Unix/X11 Windows

    Default QByteArray with network data

    Transferring data streams over a network interface using libpcap and Qt is yet again complicating and introducing much frustration into my life.

    The data to be transfered is stored in a QString in the following manner "0011223344" which is just a shorthand version of 0x00,0x11,0x22,0x33.. Data is maintained in this manner so it can be stored in a human readable text file and 0x omitted for space saving measures.

    Now in order to send this data out over the network using
    Qt Code:
    1. int pcap_sendpacket (pcap_t * p,u_char * buf, int size)
    To copy to clipboard, switch view to plain text mode 
    I must convert the QString into something u_char * compatible. A QByteArray appears to be the right container to accomplish this but I have encountered a few conversion problems.

    From the docs there does not appear to be any shortcuts for converting a QString with data stored in this manner into a QByteArray. Coding a helper function to convert the data properly should be a trivial task, but the problem occurs with type casting and being able to have the pcap_send function accept the QByteArray as a u_char * argument.

    I have tried multiple approaches in an attempt to solve this problem but all appear to be dead ends. We discussed this before in another thread but was unable to find a solution using its wisdom. Any enlightenment on the situation would be greatly appreciated.

  2. #2
    Join Date
    Feb 2006
    Thanked 541 Times in 521 Posts
    Qt products
    Unix/X11 Windows

    Default Re: QByteArray with network data

    What about QString::toAscii() and QString::toAscii().constData() - which returns (const char *).

    QString::toAscii().constData() is the same with QByteArray::constData().

    Read the docs for these functions. Seems they are what you need.


Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 04:59
  2. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 13:53
  3. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 17:17
  4. Replies: 16
    Last Post: 7th March 2006, 16:57


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.