Results 1 to 5 of 5

Thread: Null character transmission in QTcpSocket

  1. #1
    Join Date
    Jun 2010
    Location
    India
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Post Null character transmission in QTcpSocket

    hi

    I am transmitting a sequence of bytes from my Qt application onto a microcontroller. The bytes contain NULL(0x00) bytes.

    The transmission of the packet is terminated as soon as the NULL byte is encountered and the rest of the packet is discarded.

    I am using a QTcpSocket class.

    ....
    tcpSocket->write(*barr);
    while(tcpSocket->bytesToWrite() > 0)
    {
    tcpSocket->waitForBytesWritten();
    }
    ....

    Is there any way that the required number of bytes are transmitted regardless of the NULL byte? I am new to Qt so any help would be useful.

    Thanks and Regards

    Manish.S

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Null character transmission in QTcpSocket

    You should use this form of QIODevice::write functioin:
    qint64 QIODevice::write ( const char * data, qint64 maxSize )

  3. #3
    Join Date
    Jun 2010
    Location
    India
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Null character transmission in QTcpSocket

    hi

    thanks a lot for the reply

    I tried the following code but nothing seemed to work out.

    ...
    tcpSocket->write(*barr, 10);

    ...


    Though the following code gives the debug output as 10 bytes but the data is truncated as soon as the NULL bytes are encountered.

    int bytes= tcpSocket->write(*barr, 10);
    qDebug()<<"Bytes"<< bytes;


    Thanks and Regards

    Manish.S

  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Null character transmission in QTcpSocket

    1. what is a barr ?
    2. try
    qint64 QIODevice::writeData ( const char * data, qint64 maxSize )
    instead of write function
    3. try to write byte by byte like this
    Qt Code:
    1. for ( int i = 0; i < 10; i++ )
    2. {
    3. tcpSocket->write( &arr[ i ], 1 );
    4. }
    To copy to clipboard, switch view to plain text mode 
    4. How do you see, that not all of written bytes are received ?

  5. #5
    Join Date
    Jun 2010
    Location
    India
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Null character transmission in QTcpSocket

    Hi

    Thanks a lot.

    The problem was at my end. I apologize to start this thread before checking the receiving system also.

    Thanks and Regards

    Manish.S

Similar Threads

  1. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  2. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  3. NUll character output for combobox index
    By mdskpr778 in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 18:22
  4. How to terminate NULL character ?
    By merry in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2008, 20:01
  5. how to transmission a big file use the QtNetwork
    By fengtian.we in forum Qt Programming
    Replies: 9
    Last Post: 26th March 2007, 14:17

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.