summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-07-19 13:17:29 +0200
committerMitch Curtis <mitch.curtis@qt.io>2016-08-02 07:16:54 +0000
commit756a169e2530987f1b875589d196877e93704858 (patch)
tree100e459838731ca8475f4e0cf40f34549730da23
parent84a26f223b220a444dec2b43fffc71dab7e00d1d (diff)
downloadqtquickcontrols-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>
-rw-r--r--examples/quickcontrols/controls/texteditor/src/documenthandler.cpp6
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);