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.Data = new char(0); is this good?
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().
Bookmarks