[Qt-interest] Crash in ~QByteArray

Markus Goetz Markus.Goetz at nokia.com
Tue Feb 9 14:49:01 CET 2010


ext Josiah Bryan wrote:
> if(m_socket->bytesAvailable())
> 	QTimer::singleShot(0, this, SLOT(dataReady()));
> }
>   
You don't need that. After the readAll(), there should be no bytes 
available. The next readyRead() emission will call your dataReady().
> m_dataBlock is a QByteArray which gets chopped up in the processBlock() 
> method. (The processBlock() takes the images from the start of 
> m_dataBlock, leaving any incomplete images in m_dataBlock till the rest 
> of the bytes are received.)
>   
How exactly are you doing that? remove(0, len_of_first_block) ?
> I've also tried using a malloc'd buffer to dump the socket data into 
> instead of using readAll(), but it still crashed. The code was something 
> like:
>
> int bytes = m_socket->bytesAvailable();
> char * buffer = malloc(sizeof(char) * bytes);
> assert(buffer != NULL);
> int bytesRead = m_socket->read(buffer, bytes);
> m_dataBlock.append(buffer);
> free(buffer);
>   
You need to use the append(char*, int) overload, because append(char*) 
assumes 0-terminated.

Markus



More information about the Qt-interest-old mailing list