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
This commit is contained in:
Albert Astals Cid 2018-07-28 22:39:30 +02:00
parent 0646a1dcfa
commit aed8e5ac28
2 changed files with 9 additions and 5 deletions

View file

@ -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<Okular::FormFieldText *>(m_ff);
QString contents = toPlainText();
int cursorPos = textCursor().position();

View file

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