From 756a169e2530987f1b875589d196877e93704858 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 19 Jul 2016 13:17:29 +0200 Subject: 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 --- examples/quickcontrols/controls/texteditor/src/documenthandler.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'examples/quickcontrols/controls/texteditor') diff --git a/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp index 2e03f7471..b07099e26 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); -- cgit v1.2.3