From 3cea7c9927f0d7ff32bcfc1fbacde229d98e24c7 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 22 Apr 2018 19:44:48 +0200 Subject: [PATCH] Fix crash on exit when having edited a text area For some reason Q/KTextEdit is sending textChanged inside the destructor, so protect us from that. BUG: 393334 --- autotests/parttest.cpp | 15 +++++++++++++++ ui/formwidgets.cpp | 5 +++++ 2 files changed, 20 insertions(+) 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();