From aed8e5ac28a6d4f0947d6a96545fe50eb7101214 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sat, 28 Jul 2018 22:39:30 +0200 Subject: [PATCH] Fix crash on shutdown when having edited text forms This fixes the same crash as bug 393334 but in a better way the old way was setting a variable on destruction and then trying to use that variable in a slot, but that's obviously wrong since we were already mid destructing the object. BUG: 396807 --- ui/formwidgets.cpp | 13 ++++++++----- ui/formwidgets.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp index 44f29e9da..9b4ff98d4 100644 --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -293,7 +293,6 @@ FormWidgetIface::FormWidgetIface( QWidget * w, Okular::FormField * ff ) FormWidgetIface::~FormWidgetIface() { - m_ff = nullptr; } Okular::NormalizedRect FormWidgetIface::rect() const @@ -588,6 +587,14 @@ TextAreaEdit::TextAreaEdit( Okular::FormFieldText * text, QWidget * parent ) setVisible( text->isVisible() ); } +TextAreaEdit::~TextAreaEdit() +{ + // We need this because otherwise on destruction we destruct the syntax highlighter + // that ends up calling text changed but then we go to slotChanged and we're already + // half destructed and all is bad + disconnect( this, &QTextEdit::textChanged, this, &TextAreaEdit::slotChanged ); +} + bool TextAreaEdit::event( QEvent* e ) { if ( e->type() == QEvent::KeyPress ) @@ -662,10 +669,6 @@ void TextAreaEdit::slotHandleTextChangedByUndoRedo( int pageNumber, void TextAreaEdit::slotChanged() { - // happens on destruction - if (!m_ff) - return; - Okular::FormFieldText *form = static_cast(m_ff); QString contents = toPlainText(); int cursorPos = textCursor().position(); diff --git a/ui/formwidgets.h b/ui/formwidgets.h index e9d3842f1..218137172 100644 --- a/ui/formwidgets.h +++ b/ui/formwidgets.h @@ -253,6 +253,7 @@ class TextAreaEdit : public KTextEdit, public FormWidgetIface public: explicit TextAreaEdit( Okular::FormFieldText * text, QWidget * parent = nullptr ); + ~TextAreaEdit(); void setFormWidgetsController( FormWidgetsController *controller ) override; bool event ( QEvent * e ) override;