Skip to content

Commit

Permalink
TextEditor: use modern approach to delete TextEditorWidgetPrivate
Browse files Browse the repository at this point in the history
Try to tackle the crash at destruction:

https://the-qt-company-00.sentry.io/issues/5315538277
https://the-qt-company-00.sentry.io/issues/5312380342
https://the-qt-company-00.sentry.io/issues/5237253338

Change-Id: Id4436bf5adc0c725f9b5538480619ed99428413f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: hjk <hjk@qt.io>
(cherry picked from commit 310abd3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
tjenssen committed May 14, 2024
1 parent d767bfd commit dce7c79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 5 additions & 11 deletions src/plugins/texteditor/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,15 +1262,15 @@ TextEditorWidget::TextEditorWidget(QWidget *parent)
{
// "Needed", as the creation below triggers ChildEvents that are
// passed to this object's event() which uses 'd'.
d = nullptr;
d = new TextEditorWidgetPrivate(this);

d = std::make_unique<Internal::TextEditorWidgetPrivate>(this);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setLayoutDirection(Qt::LeftToRight);
viewport()->setMouseTracking(true);
setFrameStyle(QFrame::NoFrame);
}

TextEditorWidget::~TextEditorWidget() = default;

void TextEditorWidget::setTextDocument(const QSharedPointer<TextDocument> &doc)
{
d->setDocument(doc);
Expand Down Expand Up @@ -1449,12 +1449,6 @@ void TextEditorWidgetPrivate::setDocument(const QSharedPointer<TextDocument> &do
setupFromDefinition(currentDefinition());
}

TextEditorWidget::~TextEditorWidget()
{
delete d;
d = nullptr;
}

void TextEditorWidget::print(QPrinter *printer)
{
const bool oldFullPage = printer->fullPage();
Expand Down Expand Up @@ -5796,7 +5790,7 @@ void TextEditorWidgetPrivate::paintRevisionMarker(QPainter &painter,

void TextEditorWidget::extraAreaPaintEvent(QPaintEvent *e)
{
ExtraAreaPaintEventData data(this, d);
ExtraAreaPaintEventData data(this, d.get());
QTC_ASSERT(data.documentLayout, return);

QPainter painter(d->m_extraArea);
Expand Down Expand Up @@ -9402,7 +9396,7 @@ void TextEditorWidget::setupGenericHighlighter()
setLineSeparatorsAllowed(true);

connect(textDocument(), &IDocument::filePathChanged,
d, &TextEditorWidgetPrivate::reconfigure);
d.get(), &TextEditorWidgetPrivate::reconfigure);
}

//
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/texteditor/texteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class TEXTEDITOR_EXPORT TextEditorWidget : public QPlainTextEdit
virtual void slotCodeStyleSettingsChanged(const QVariant &); // Used in CppEditor

private:
Internal::TextEditorWidgetPrivate *d;
std::unique_ptr<Internal::TextEditorWidgetPrivate> d;
friend class BaseTextEditor;
friend class TextEditorFactory;
friend class Internal::TextEditorFactoryPrivate;
Expand Down

0 comments on commit dce7c79

Please sign in to comment.