Results 1 to 11 of 11

Thread: Qt Data transfer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Data transfer

    Data = new char(0); is this good?
    No. With this statement, you are allocating memory for a single char, setting the char's value to zero, and assigning the resulting pointer to your variable Data. And when you later use that variable and tell the read() method that it points to enough memory to hold 5 bytes, well, that's a lie. It points to memory big enough to hold one byte, and so read() cheerfully overwrites the memory for whatever is allocated after the Data pointer. Do that enough times or for a large enough read and you're bound to trash something critical, and there goes your program.

    If you want to dynamically allocate the buffer, then you should use QAbstractSocket::bytesAvailable() to find out what is waiting, then allocate your array to that size before calling read().

  2. The following user says thank you to d_stranz for this useful post:

    Shibby284 (25th July 2015)

  3. #2
    Join Date
    Jul 2015
    Posts
    13
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Data transfer

    well, this is what i wrote:

    buffer_size = socket->bytesAvailable();

    Data = (char *)malloc(sizeof(char)*buffer_size);

    BytesRead = socket->read(Data,buffer_size);

    BytesWritten = process1->write(Data,BytesRead);

    free(Data);

    the thing is i got back to the starting point where i allocate memroy and release it every time i read/write. Due to this(or some other reason i still don't understand)
    the video that is being recieved is very very slow.

    Could it be the gui that slows it down? i checked the cpu performance and it doesn't take a lot of it..

    thanks.

Similar Threads

  1. Fastest way to transfer Data over tcp
    By Qiieha in forum General Programming
    Replies: 21
    Last Post: 29th July 2012, 18:11
  2. Data transfer using TCP Socket
    By rex in forum Qt Programming
    Replies: 0
    Last Post: 24th March 2011, 16:06
  3. Data transfer between QIODevice
    By benlau in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2010, 05:59
  4. Transfer Data Between Dialogs
    By umulingu in forum Qt Programming
    Replies: 4
    Last Post: 19th February 2010, 08:35

Tags for this Thread

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.