diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index c8688f2fba5..d1a11b4e9ca 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -53,12 +53,12 @@ RefactoringFile::RefactoringFile(const FilePath &filePath) : m_filePath(filePath bool RefactoringFile::create(const QString &contents, bool reindent, bool openInEditor) { - if (m_filePath.isEmpty() || m_filePath.exists() || m_editor) + if (m_filePath.isEmpty() || m_filePath.exists() || m_editor || m_document) return false; // Create a text document for the new file: - auto document = new QTextDocument; - QTextCursor cursor(document); + m_document = new QTextDocument; + QTextCursor cursor(m_document); cursor.beginEditBlock(); cursor.insertText(contents); @@ -74,8 +74,9 @@ bool RefactoringFile::create(const QString &contents, bool reindent, bool openIn TextFileFormat format; format.codec = EditorManager::defaultTextCodec(); QString error; - bool saveOk = format.writeFile(m_filePath, document->toPlainText(), &error); - delete document; + bool saveOk = format.writeFile(m_filePath, m_document->toPlainText(), &error); + delete m_document; + m_document = nullptr; if (!saveOk) return false;