From d21da6df2d52cb8e362525f6c8a578b18fa03a9e Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 24 Jun 2022 19:01:10 -0700 Subject: [PATCH] Qt: Fix crash when calling createBuffer from a callback --- src/platform/qt/scripting/ScriptingTextBuffer.h | 2 +- src/platform/qt/scripting/ScriptingTextBufferModel.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/platform/qt/scripting/ScriptingTextBuffer.h b/src/platform/qt/scripting/ScriptingTextBuffer.h index e2bdb8f30..b70e9f82a 100644 --- a/src/platform/qt/scripting/ScriptingTextBuffer.h +++ b/src/platform/qt/scripting/ScriptingTextBuffer.h @@ -18,7 +18,7 @@ class ScriptingTextBuffer : public QObject { Q_OBJECT public: - ScriptingTextBuffer(QObject* parent); + ScriptingTextBuffer(QObject* parent = nullptr); QTextDocument* document() { return &m_document; }; mScriptTextBuffer* textBuffer() { return &m_shim; } diff --git a/src/platform/qt/scripting/ScriptingTextBufferModel.cpp b/src/platform/qt/scripting/ScriptingTextBufferModel.cpp index 0d01b7581..d62bb62df 100644 --- a/src/platform/qt/scripting/ScriptingTextBufferModel.cpp +++ b/src/platform/qt/scripting/ScriptingTextBufferModel.cpp @@ -35,7 +35,11 @@ void ScriptingTextBufferModel::reset() { mScriptTextBuffer* ScriptingTextBufferModel::createTextBuffer(void* context) { ScriptingTextBufferModel* self = static_cast(context); self->beginInsertRows(QModelIndex(), self->m_buffers.size(), self->m_buffers.size() + 1); - ScriptingTextBuffer* buffer = new ScriptingTextBuffer(self); + ScriptingTextBuffer* buffer = new ScriptingTextBuffer; + if (buffer->thread() != self->thread()) { + buffer->moveToThread(self->thread()); + } + buffer->setParent(self); QObject::connect(buffer, &ScriptingTextBuffer::bufferNameChanged, self, &ScriptingTextBufferModel::bufferNameChanged); self->m_buffers.append(buffer); emit self->textBufferCreated(buffer);