[Qt-interest] Crash in ~QByteArray
Josiah Bryan
jbryan at productiveconcepts.com
Tue Feb 9 14:59:27 CET 2010
Markus Goetz wrote:
> 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().
You're right - legacy leftover from another project. Removed.
>> 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) ?
Yes.
In processBlock(), it does something like:
int idx = [image boundary index];
QByteArray block = m_dataBlock.left(idx);
m_dataBlock.remove(0,idx);
[process 'block' by removing headers and reading into a QImage]
>> 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.
You're right - that code was all from memory - I think the
append(char*,int) was the form I used - I'd have to go back and check
subversion, but regardless, you are correct.
Does any of this info help with the crashing though?
Thanks!
-josiah
More information about the Qt-interest-old
mailing list