diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-04-12 18:32:35 +0200 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-04-17 15:09:56 +0200 |
commit | d1347ebbe99b467799680bb6e3cee81932751df5 (patch) | |
tree | a2511878f488a12da57b5311dc6d53ceb14a1990 /src | |
parent | 2c80ff478bcc3290cafd970c5fd3412f2887fc91 (diff) | |
download | qtwebengine-d1347ebbe99b467799680bb6e3cee81932751df5.tar.gz |
Clear PDF search results on document page model change
Not clearing the search results leads to crashes when the incoming
page model is larger than the outgoing model, due to internal
state being still in sync with the old document, but the page count
of the new document being used.
Fixes: QTBUG-111067
Pick-to: 6.5
Change-Id: Ic81744ebe0cb7d1a152453721abd7d1b5c5fa2b9
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/pdf/qpdfsearchmodel.cpp | 12 | ||||
-rw-r--r-- | src/pdf/qpdfsearchmodel.h | 1 | ||||
-rw-r--r-- | src/pdf/qpdfsearchmodel_p.h | 2 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/pdf/qpdfsearchmodel.cpp b/src/pdf/qpdfsearchmodel.cpp index 7fe11c2fe..3109430f0 100644 --- a/src/pdf/qpdfsearchmodel.cpp +++ b/src/pdf/qpdfsearchmodel.cpp @@ -194,11 +194,23 @@ void QPdfSearchModel::setDocument(QPdfDocument *document) if (d->document == document) return; + disconnect(d->documentConnection); + d->documentConnection = connect(document, &QPdfDocument::pageCountChanged, this, + &QPdfSearchModel::onDocumentPageCountChanged); + d->document = document; d->clearResults(); emit documentChanged(); } +void QPdfSearchModel::onDocumentPageCountChanged(int count) +{ + Q_UNUSED(count); + + Q_D(QPdfSearchModel); + d->clearResults(); +} + void QPdfSearchModel::timerEvent(QTimerEvent *event) { Q_D(QPdfSearchModel); diff --git a/src/pdf/qpdfsearchmodel.h b/src/pdf/qpdfsearchmodel.h index c1e4e64ec..b1094b67b 100644 --- a/src/pdf/qpdfsearchmodel.h +++ b/src/pdf/qpdfsearchmodel.h @@ -55,6 +55,7 @@ Q_SIGNALS: protected: void updatePage(int page); void timerEvent(QTimerEvent *event) override; + void onDocumentPageCountChanged(int count); private: QHash<int, QByteArray> m_roleNames; diff --git a/src/pdf/qpdfsearchmodel_p.h b/src/pdf/qpdfsearchmodel_p.h index 4922c81e9..5ffa08f5d 100644 --- a/src/pdf/qpdfsearchmodel_p.h +++ b/src/pdf/qpdfsearchmodel_p.h @@ -45,6 +45,8 @@ public: int rowCountSoFar = 0; int updateTimerId = -1; int nextPageToUpdate = 0; + + QMetaObject::Connection documentConnection; }; QT_END_NAMESPACE |