diff --git a/autotests/parttest.cpp b/autotests/parttest.cpp index f2932fb1e..1fb0c2f88 100644 --- a/autotests/parttest.cpp +++ b/autotests/parttest.cpp @@ -21,6 +21,7 @@ #include "../generators/poppler/config-okular-poppler.h" +#include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +110,7 @@ class PartTest void testClickAnywhereAfterSelectionShouldUnselect(); void testeRectSelectionStartingOnLinks(); void testCheckBoxReadOnly(); + void testCrashTextEditDestroy(); private: void simulateMouseSelection(double startX, double startY, double endX, double endY, QWidget *target); @@ -1399,6 +1402,18 @@ void PartTest::testCheckBoxReadOnly() QVERIFY( !targetDefaultRO->isReadOnly() ); } +void PartTest::testCrashTextEditDestroy() +{ + const QString testFile = QStringLiteral( KDESRCDIR "data/formSamples.pdf" ); + Okular::Part part( nullptr, nullptr, QVariantList() ); + part.openDocument( testFile ); + part.widget()->show(); + QVERIFY(QTest::qWaitForWindowExposed(part.widget())); + + part.widget()->findChild()->setText("HOLA"); + part.actionCollection()->action(QStringLiteral("view_toggle_forms"))->trigger(); +} + } int main(int argc, char *argv[]) diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp index 68f459571..b75ba5123 100644 --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -292,6 +292,7 @@ FormWidgetIface::FormWidgetIface( QWidget * w, Okular::FormField * ff ) FormWidgetIface::~FormWidgetIface() { + m_ff = nullptr; } Okular::NormalizedRect FormWidgetIface::rect() const @@ -668,6 +669,10 @@ 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();