Read (append) all data to an additional buffer and try creating the dom tree out of that. Once QDomDocument::setContent() is successful, you know you received the full DOM tree. Then you just have to check how much of the data to discard from the buffer (there can be more data waiting in the buffer).