Qt: Fix crash when calling createBuffer from a callback

This commit is contained in:
Vicki Pfau 2022-06-24 19:01:10 -07:00
parent e8a39fea95
commit d21da6df2d
2 changed files with 6 additions and 2 deletions

View File

@ -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; }

View File

@ -35,7 +35,11 @@ void ScriptingTextBufferModel::reset() {
mScriptTextBuffer* ScriptingTextBufferModel::createTextBuffer(void* context) {
ScriptingTextBufferModel* self = static_cast<ScriptingTextBufferModel*>(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);