Try creating a cursur like that
QTextCursor c(document);

where document is your QTextDocument*


If that makes no difference:
call position() on the cursor before doing the selection, and restore (only) the position when you're done with setPosition.



Not sure if it will work, but worth a try.

Good luck!