[Interest] QQuickTextDocument and changing internal state of QTextDocument

Alan Alpert 416365416c at gmail.com
Fri Jul 5 18:42:25 CEST 2013


On Fri, Jun 28, 2013 at 4:35 AM, Cornelius Hald <hald at icandy.de> wrote:
> Hi,
>
> I'm very happy to see that it is finally possible to get the
> QTextDocument of an QtQuick TextEdit element. Unfortunately the
> documentation for QQuickTextDocument states the following:
>
> ------
> You are not allowed to modify the document, [...]
>
> Warning: The QTextDocument provided is used internally by QtQuick
> elements to provide text manipulation primitives.
>
> You are not allowed to perform any modification of the internal state of
> the QTextDocument. If you do, the element in question may stop
> functioning or crash.
> ------
>
> Does anyone knows what exactly that means? I've written a small sample
> that edits the document, for example by removing characters. So far
> nothing has crashed yet.
>
> // Seems to work fine...
> QTextCursor c(m_document);
> c.movePosition(QTextCursor::StartOfBlock);
> c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
> c.removeSelectedText();
>
> Since I'm thinking about doing an editor on top of QtQuick 2.1, I'd be
> happy to first know the exact limitations of this approach.

The generic warning is there because, unfortunately, the exact
limitations have not yet been delineated. QQuickTextEdit uses the
document for rendering and layout, so the risk is that if you modify
the document in a way it didn't expect then the element can enter a
messed up state. When it comes to modifying the state, beyond adding
text blocks or formatting hints, the implications have not been
considered fully.

This is because adding the formatting hints was vital and known to be
safe, so we put it out there for that usecase and we extend the
recommended usage later when we have time.

--
Alan Alpert



More information about the Interest mailing list