diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-07-19 13:17:29 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-08-02 07:16:54 +0000 |
commit | 756a169e2530987f1b875589d196877e93704858 (patch) | |
tree | 100e459838731ca8475f4e0cf40f34549730da23 /examples | |
parent | 84a26f223b220a444dec2b43fffc71dab7e00d1d (diff) | |
download | qtquickcontrols-756a169e2530987f1b875589d196877e93704858.tar.gz |
texteditor example: check if document is null before using it
This hasn't been an issue so far probably because those properties were
accessed after m_doc had been set. However, adding some debug text can
trigger a crash:
Text {
text: "document.cursorPosition=" + document.cursorPosition
}
Change-Id: Ib468815cdc0b103a2384457ab937cc3b764b96c8
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quickcontrols/controls/texteditor/src/documenthandler.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp index 2e03f747..b07099e2 100644 --- a/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp +++ b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp @@ -169,6 +169,9 @@ void DocumentHandler::reset() QTextCursor DocumentHandler::textCursor() const { + if (!m_doc) + return QTextCursor(); + QTextCursor cursor = QTextCursor(m_doc); if (m_selectionStart != m_selectionEnd) { cursor.setPosition(m_selectionStart); @@ -199,6 +202,9 @@ void DocumentHandler::setSelectionEnd(int position) void DocumentHandler::setAlignment(Qt::Alignment a) { + if (!m_doc) + return; + QTextBlockFormat fmt; fmt.setAlignment((Qt::Alignment) a); QTextCursor cursor = QTextCursor(m_doc); |