Results 1 to 2 of 2

Thread: QTcpSocket Write & \0 \x00

  1. #1
    Join Date
    Apr 2010
    Posts
    1
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Windows

    Default QTcpSocket Write & \0 \x00

    Hello, I'm pretty new to QT well even C in general, so please bear with me ^^

    Basically I'm playing around with sockets and such, and I need to write a strick to the socket server with "\x00" attached to the end of the string, but apparently it's not as easy as that.

    for example if I do
    socket->write("data\x00");
    it will only send "data" and not the appending null character..

    So I was hoping you guys could point me in the right direction

  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: QTcpSocket Write & \0 \x00

    \0 is interpreted as the end of a string so appending it to a string will have no useful result without telling the callee the size of the character array. So either don't append null bytes to the array (as it already contains a null character at the end) and/or pass the size of the array to the callee. Or use QByteArray:
    Qt Code:
    1. QByteArray ba = "data";
    2. ba.append('\0');
    3. socket->write(ba);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. read and write on qtcpsocket
    By dognzhe in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 09:42
  2. QTcpSocket waiting for write to be read
    By spraff in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 19:12
  3. TCP Write Raw data
    By ^NyAw^ in forum General Programming
    Replies: 19
    Last Post: 23rd November 2007, 16:38
  4. XML -read-write
    By hgedek in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2007, 18:10
  5. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55

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.