[poppler] qt6/demos qt6/src qt6/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 19 21:58:35 UTC 2021


 qt6/demos/documentobserver.cpp           |    2 
 qt6/demos/pageview.cpp                   |    3 
 qt6/demos/thumbnails.cpp                 |    3 
 qt6/demos/viewer.cpp                     |   15 +---
 qt6/demos/viewer.h                       |    4 -
 qt6/src/poppler-annotation-private.h     |    6 +
 qt6/src/poppler-annotation.cc            |   92 ++++++++++++--------------
 qt6/src/poppler-annotation.h             |   15 +---
 qt6/src/poppler-document.cc              |   46 +++++++------
 qt6/src/poppler-form.cc                  |   28 ++++----
 qt6/src/poppler-form.h                   |    8 +-
 qt6/src/poppler-link-extractor-private.h |    8 +-
 qt6/src/poppler-link-extractor.cc        |   16 +---
 qt6/src/poppler-link-private.h           |    2 
 qt6/src/poppler-link.cc                  |   14 ++--
 qt6/src/poppler-link.h                   |    4 -
 qt6/src/poppler-page-private.h           |    4 -
 qt6/src/poppler-page.cc                  |  106 ++++++++++++++-----------------
 qt6/src/poppler-private.h                |    2 
 qt6/src/poppler-qt6.h                    |   94 +++++++++------------------
 qt6/tests/check_actualtext.cpp           |   22 ++----
 qt6/tests/check_annotations.cpp          |   27 ++-----
 qt6/tests/check_attachments.cpp          |   27 +------
 qt6/tests/check_fonts.cpp                |   63 +++++-------------
 qt6/tests/check_forms.cpp                |   68 +++++++++----------
 qt6/tests/check_links.cpp                |   64 ++++++------------
 qt6/tests/check_metadata.cpp             |   91 +++++---------------------
 qt6/tests/check_optcontent.cpp           |   20 +----
 qt6/tests/check_pagelayout.cpp           |   15 ----
 qt6/tests/check_pagemode.cpp             |   25 +------
 qt6/tests/check_password.cpp             |   40 ++---------
 qt6/tests/check_permissions.cpp          |    5 -
 qt6/tests/check_search.cpp               |   30 ++++----
 qt6/tests/check_stroke_opacity.cpp       |    2 
 qt6/tests/poppler-attachments.cpp        |    3 
 qt6/tests/poppler-fonts.cpp              |    3 
 qt6/tests/poppler-forms.cpp              |   19 ++---
 qt6/tests/poppler-page-labels.cpp        |    3 
 qt6/tests/poppler-texts.cpp              |    6 -
 qt6/tests/stress-poppler-dir.cpp         |    7 --
 qt6/tests/stress-poppler-qt6.cpp         |    6 -
 qt6/tests/stress-threads-qt6.cpp         |   47 +++++--------
 qt6/tests/test-password-qt6.cpp          |   22 ++----
 qt6/tests/test-poppler-qt6.cpp           |   36 +++-------
 qt6/tests/test-render-to-file.cpp        |    6 -
 45 files changed, 433 insertions(+), 696 deletions(-)

New commits:
commit 45717a50c52ab13f405584eab4e1c586bd39a0ce
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Wed May 19 21:58:33 2021 +0000

    Use std::unique_ptr in the Qt6 interface

diff --git a/qt6/demos/documentobserver.cpp b/qt6/demos/documentobserver.cpp
index 5bf41ac8..31551fa1 100644
--- a/qt6/demos/documentobserver.cpp
+++ b/qt6/demos/documentobserver.cpp
@@ -26,7 +26,7 @@ DocumentObserver::~DocumentObserver() { }
 
 Poppler::Document *DocumentObserver::document() const
 {
-    return m_viewer->m_doc;
+    return m_viewer->m_doc.get();
 }
 
 void DocumentObserver::setPage(int page)
diff --git a/qt6/demos/pageview.cpp b/qt6/demos/pageview.cpp
index 21812cad..edc6f353 100644
--- a/qt6/demos/pageview.cpp
+++ b/qt6/demos/pageview.cpp
@@ -47,7 +47,7 @@ void PageView::documentClosed()
 
 void PageView::pageChanged(int page)
 {
-    Poppler::Page *popplerPage = document()->page(page);
+    std::unique_ptr<Poppler::Page> popplerPage = document()->page(page);
 
     if (!popplerPage) {
         qDebug() << "Page" << page << "is malformed";
@@ -74,7 +74,6 @@ void PageView::pageChanged(int page)
         m_imageLabel->resize(0, 0);
         m_imageLabel->setPixmap(QPixmap());
     }
-    delete popplerPage;
 }
 
 void PageView::slotZoomChanged(qreal value)
diff --git a/qt6/demos/thumbnails.cpp b/qt6/demos/thumbnails.cpp
index 4aca61e9..060bf5e5 100644
--- a/qt6/demos/thumbnails.cpp
+++ b/qt6/demos/thumbnails.cpp
@@ -44,7 +44,7 @@ void ThumbnailsDock::fillInfo()
     const int num = document()->numPages();
     QSize maxSize;
     for (int i = 0; i < num; ++i) {
-        const Poppler::Page *page = document()->page(i);
+        const std::unique_ptr<Poppler::Page> page = document()->page(i);
         const QImage image = page ? page->thumbnail() : QImage();
         if (!image.isNull()) {
             QListWidgetItem *item = new QListWidgetItem();
@@ -55,7 +55,6 @@ void ThumbnailsDock::fillInfo()
             maxSize.setWidth(qMax(maxSize.width(), image.width()));
             maxSize.setHeight(qMax(maxSize.height(), image.height()));
         }
-        delete page;
     }
     if (num > 0) {
         m_list->setGridSize(maxSize);
diff --git a/qt6/demos/viewer.cpp b/qt6/demos/viewer.cpp
index b2a9c1b3..394d8f7a 100644
--- a/qt6/demos/viewer.cpp
+++ b/qt6/demos/viewer.cpp
@@ -173,7 +173,7 @@ void PdfViewer::loadDocument(const QString &file)
 {
     // resetting xrefReconstructed each time we load new document
     xrefReconstructed = false;
-    Poppler::Document *newdoc = Poppler::Document::load(file);
+    std::unique_ptr<Poppler::Document> newdoc = Poppler::Document::load(file);
     if (!newdoc) {
         QMessageBox msgbox(QMessageBox::Critical, tr("Open Error"), tr("Cannot open:\n") + file, QMessageBox::Ok, this);
         msgbox.exec();
@@ -184,7 +184,6 @@ void PdfViewer::loadDocument(const QString &file)
         bool ok = true;
         QString password = QInputDialog::getText(this, tr("Document Password"), tr("Please insert the password of the document:"), QLineEdit::Password, QString(), &ok);
         if (!ok) {
-            delete newdoc;
             return;
         }
         newdoc->unlock(password.toLatin1(), password.toLatin1());
@@ -192,15 +191,15 @@ void PdfViewer::loadDocument(const QString &file)
 
     closeDocument();
 
-    m_doc = newdoc;
+    m_doc = std::move(newdoc);
 
     m_doc->setRenderHint(Poppler::Document::TextAntialiasing, m_settingsTextAAAct->isChecked());
     m_doc->setRenderHint(Poppler::Document::Antialiasing, m_settingsGfxAAAct->isChecked());
     m_doc->setRenderBackend((Poppler::Document::RenderBackend)m_settingsRenderBackendGrp->checkedAction()->data().toInt());
     if (m_doc->xrefWasReconstructed()) {
-        xrefReconstructedHandler(m_doc);
+        xrefReconstructedHandler();
     } else {
-        std::function<void()> cb = [this]() { xrefReconstructedHandler(m_doc); };
+        std::function<void()> cb = [this]() { xrefReconstructedHandler(); };
 
         m_doc->setXRefReconstructedCallback(cb);
     }
@@ -224,13 +223,12 @@ void PdfViewer::closeDocument()
     }
 
     m_currentPage = 0;
-    delete m_doc;
     m_doc = nullptr;
 
     m_fileSaveCopyAct->setEnabled(false);
 }
 
-void PdfViewer::xrefReconstructedHandler(Poppler::Document *doc)
+void PdfViewer::xrefReconstructedHandler()
 {
     if (!xrefReconstructed) {
         QMessageBox msgbox(QMessageBox::Critical, tr("File may be corrupted"), tr("The PDF may be broken but we're still showing something, contents may not be correct"), QMessageBox::Ok, this);
@@ -261,13 +259,12 @@ void PdfViewer::slotSaveCopy()
         return;
     }
 
-    Poppler::PDFConverter *converter = m_doc->pdfConverter();
+    std::unique_ptr<Poppler::PDFConverter> converter = m_doc->pdfConverter();
     converter->setOutputFileName(fileName);
     converter->setPDFOptions(converter->pdfOptions() & ~Poppler::PDFConverter::WithChanges);
     if (!converter->convert()) {
         QMessageBox msgbox(QMessageBox::Critical, tr("Save Error"), tr("Cannot export to:\n%1").arg(fileName), QMessageBox::Ok, this);
     }
-    delete converter;
 }
 
 void PdfViewer::slotAbout()
diff --git a/qt6/demos/viewer.h b/qt6/demos/viewer.h
index 8f2ee3a2..5c3bedb5 100644
--- a/qt6/demos/viewer.h
+++ b/qt6/demos/viewer.h
@@ -57,7 +57,7 @@ private Q_SLOTS:
 private:
     void setPage(int page);
     int page() const;
-    void xrefReconstructedHandler(Poppler::Document *doc);
+    void xrefReconstructedHandler();
 
     int m_currentPage;
     bool xrefReconstructed;
@@ -70,7 +70,7 @@ private:
 
     QList<DocumentObserver *> m_observers;
 
-    Poppler::Document *m_doc;
+    std::unique_ptr<Poppler::Document> m_doc;
 };
 
 #endif
diff --git a/qt6/src/poppler-annotation-private.h b/qt6/src/poppler-annotation-private.h
index 1e8b6d32..9e2c1e7e 100644
--- a/qt6/src/poppler-annotation-private.h
+++ b/qt6/src/poppler-annotation-private.h
@@ -23,6 +23,8 @@
 #ifndef _POPPLER_ANNOTATION_PRIVATE_H_
 #define _POPPLER_ANNOTATION_PRIVATE_H_
 
+#include <memory>
+
 #include <QtCore/QPointF>
 #include <QtCore/QSharedDataPointer>
 
@@ -96,7 +98,7 @@ public:
     AnnotPath *toAnnotPath(const QVector<QPointF> &l) const;
 
     /* Scan page for annotations, parentId=0 searches for root annotations, subtypes empty means all subtypes */
-    static QList<Annotation *> findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentId = -1);
+    static std::vector<std::unique_ptr<Annotation>> findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentId = -1);
 
     /* Add given annotation to given page */
     static void addAnnotationToPage(::Page *pdfPage, DocumentData *doc, const Annotation *ann);
@@ -106,7 +108,7 @@ public:
 
     Ref pdfObjectReference() const;
 
-    Link *additionalAction(Annotation::AdditionalActionType type) const;
+    std::unique_ptr<Link> additionalAction(Annotation::AdditionalActionType type) const;
 };
 
 }
diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc
index 4b31cece..337ed898 100644
--- a/qt6/src/poppler-annotation.cc
+++ b/qt6/src/poppler-annotation.cc
@@ -10,7 +10,7 @@
  * Copyright (C) 2018 Dileep Sankhla <sankhla.dileep96 at gmail.com>
  * Copyright (C) 2018, 2019 Tobias Deiminger <haxtibal at posteo.de>
  * Copyright (C) 2018 Carlos Garcia Campos <carlosgc at gnome.org>
- * Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2020, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2020 Katarina Behrens <Katarina.Behrens at cib.de>
  * Copyright (C) 2020 Thorsten Behrens <Thorsten.Behrens at CIB.de>
  * Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by Technische Universität Dresden
@@ -295,12 +295,12 @@ AnnotPath *AnnotationPrivate::toAnnotPath(const QVector<QPointF> &list) const
     return new AnnotPath(std::move(ac));
 }
 
-QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentID)
+std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentID)
 {
     Annots *annots = pdfPage->getAnnots();
     const uint numAnnotations = annots->getNumAnnots();
     if (numAnnotations == 0) {
-        return QList<Annotation *>();
+        return std::vector<std::unique_ptr<Annotation>>();
     }
 
     const bool wantTextAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AText);
@@ -318,7 +318,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
     const bool wantWidgetAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AWidget);
 
     // Create Annotation objects and tie to their native Annot
-    QList<Annotation *> res;
+    std::vector<std::unique_ptr<Annotation>> res;
     for (uint k = 0; k < numAnnotations; k++) {
         // get the j-th annotation
         Annot *ann = annots->getAnnot(k);
@@ -337,36 +337,36 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
             continue;
 
         /* Create Annotation of the right subclass */
-        Annotation *annotation = nullptr;
+        std::unique_ptr<Annotation> annotation;
         Annot::AnnotSubtype subType = ann->getType();
 
         switch (subType) {
         case Annot::typeText:
             if (!wantTextAnnotations)
                 continue;
-            annotation = new TextAnnotation(TextAnnotation::Linked);
+            annotation = std::make_unique<TextAnnotation>(TextAnnotation::Linked);
             break;
         case Annot::typeFreeText:
             if (!wantTextAnnotations)
                 continue;
-            annotation = new TextAnnotation(TextAnnotation::InPlace);
+            annotation = std::make_unique<TextAnnotation>(TextAnnotation::InPlace);
             break;
         case Annot::typeLine:
             if (!wantLineAnnotations)
                 continue;
-            annotation = new LineAnnotation(LineAnnotation::StraightLine);
+            annotation = std::make_unique<LineAnnotation>(LineAnnotation::StraightLine);
             break;
         case Annot::typePolygon:
         case Annot::typePolyLine:
             if (!wantLineAnnotations)
                 continue;
-            annotation = new LineAnnotation(LineAnnotation::Polyline);
+            annotation = std::make_unique<LineAnnotation>(LineAnnotation::Polyline);
             break;
         case Annot::typeSquare:
         case Annot::typeCircle:
             if (!wantGeomAnnotations)
                 continue;
-            annotation = new GeomAnnotation();
+            annotation = std::make_unique<GeomAnnotation>();
             break;
         case Annot::typeHighlight:
         case Annot::typeUnderline:
@@ -374,17 +374,17 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
         case Annot::typeStrikeOut:
             if (!wantHighlightAnnotations)
                 continue;
-            annotation = new HighlightAnnotation();
+            annotation = std::make_unique<HighlightAnnotation>();
             break;
         case Annot::typeStamp:
             if (!wantStampAnnotations)
                 continue;
-            annotation = new StampAnnotation();
+            annotation = std::make_unique<StampAnnotation>();
             break;
         case Annot::typeInk:
             if (!wantInkAnnotations)
                 continue;
-            annotation = new InkAnnotation();
+            annotation = std::make_unique<InkAnnotation>();
             break;
         case Annot::typeLink: /* TODO: Move logic to getters */
         {
@@ -393,7 +393,6 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
             // parse Link params
             AnnotLink *linkann = static_cast<AnnotLink *>(ann);
             LinkAnnotation *l = new LinkAnnotation();
-            annotation = l;
 
             // -> hlMode
             l->setLinkHighlightMode((LinkAnnotation::HighlightMode)linkann->getLinkEffect());
@@ -403,17 +402,18 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
 
             // reading link action
             if (linkann->getAction()) {
-                Link *popplerLink = PageData::convertLinkActionToLink(linkann->getAction(), doc, QRectF());
+                std::unique_ptr<Link> popplerLink = PageData::convertLinkActionToLink(linkann->getAction(), doc, QRectF());
                 if (popplerLink) {
-                    l->setLinkDestination(popplerLink);
+                    l->setLinkDestination(std::move(popplerLink));
                 }
             }
+            annotation.reset(l);
             break;
         }
         case Annot::typeCaret:
             if (!wantCaretAnnotations)
                 continue;
-            annotation = new CaretAnnotation();
+            annotation = std::make_unique<CaretAnnotation>();
             break;
         case Annot::typeFileAttachment: /* TODO: Move logic to getters */
         {
@@ -421,12 +421,12 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
                 continue;
             AnnotFileAttachment *attachann = static_cast<AnnotFileAttachment *>(ann);
             FileAttachmentAnnotation *f = new FileAttachmentAnnotation();
-            annotation = f;
             // -> fileIcon
             f->setFileIconName(QString::fromLatin1(attachann->getName()->c_str()));
             // -> embeddedFile
             FileSpec *filespec = new FileSpec(attachann->getFile());
             f->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(filespec)));
+            annotation.reset(f);
             break;
         }
         case Annot::typeSound: /* TODO: Move logic to getters */
@@ -435,12 +435,12 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
                 continue;
             AnnotSound *soundann = static_cast<AnnotSound *>(ann);
             SoundAnnotation *s = new SoundAnnotation();
-            annotation = s;
 
             // -> soundIcon
             s->setSoundIconName(QString::fromLatin1(soundann->getName()->c_str()));
             // -> sound
             s->setSound(new SoundObject(soundann->getSound()));
+            annotation.reset(s);
             break;
         }
         case Annot::typeMovie: /* TODO: Move logic to getters */
@@ -449,7 +449,6 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
                 continue;
             AnnotMovie *movieann = static_cast<AnnotMovie *>(ann);
             MovieAnnotation *m = new MovieAnnotation();
-            annotation = m;
 
             // -> movie
             MovieObject *movie = new MovieObject(movieann);
@@ -458,6 +457,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
             const GooString *movietitle = movieann->getTitle();
             if (movietitle)
                 m->setMovieTitle(QString::fromLatin1(movietitle->c_str()));
+            annotation.reset(m);
             break;
         }
         case Annot::typeScreen: {
@@ -468,16 +468,16 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
             if (!screenann->getAction() || screenann->getAction()->getKind() != actionRendition)
                 continue;
             ScreenAnnotation *s = new ScreenAnnotation();
-            annotation = s;
 
             // -> screen
-            Link *popplerLink = PageData::convertLinkActionToLink(screenann->getAction(), doc, QRectF());
-            s->setAction(static_cast<Poppler::LinkRendition *>(popplerLink));
+            std::unique_ptr<Link> popplerLink = PageData::convertLinkActionToLink(screenann->getAction(), doc, QRectF());
+            s->setAction(static_cast<Poppler::LinkRendition *>(popplerLink.release()));
 
             // -> screenTitle
             const GooString *screentitle = screenann->getTitle();
             if (screentitle)
                 s->setScreenTitle(UnicodeParsedString(screentitle));
+            annotation.reset(s);
             break;
         }
         case Annot::typePopup:
@@ -487,7 +487,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
         case Annot::typeWidget:
             if (!wantWidgetAnnotations)
                 continue;
-            annotation = new WidgetAnnotation();
+            annotation.reset(new WidgetAnnotation());
             break;
         case Annot::typeRichMedia: {
             const AnnotRichMedia *annotRichMedia = static_cast<AnnotRichMedia *>(ann);
@@ -644,7 +644,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
                 richMediaAnnotation->setContent(content);
             }
 
-            annotation = richMediaAnnotation;
+            annotation.reset(richMediaAnnotation);
 
             break;
         }
@@ -667,7 +667,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
         }
 
         annotation->d_ptr->tieToNativeAnnot(ann, pdfPage, doc);
-        res.append(annotation);
+        res.push_back(std::move(annotation));
     }
 
     return res;
@@ -682,25 +682,23 @@ Ref AnnotationPrivate::pdfObjectReference() const
     return pdfAnnot->getRef();
 }
 
-Link *AnnotationPrivate::additionalAction(Annotation::AdditionalActionType type) const
+std::unique_ptr<Link> AnnotationPrivate::additionalAction(Annotation::AdditionalActionType type) const
 {
     if (pdfAnnot->getType() != Annot::typeScreen && pdfAnnot->getType() != Annot::typeWidget)
-        return nullptr;
+        return {};
 
     const Annot::AdditionalActionsType actionType = toPopplerAdditionalActionType(type);
 
-    std::unique_ptr<::LinkAction> linkAction = nullptr;
+    std::unique_ptr<::LinkAction> linkAction;
     if (pdfAnnot->getType() == Annot::typeScreen)
         linkAction = static_cast<AnnotScreen *>(pdfAnnot)->getAdditionalAction(actionType);
     else
         linkAction = static_cast<AnnotWidget *>(pdfAnnot)->getAdditionalAction(actionType);
 
-    Link *link = nullptr;
-
     if (linkAction)
-        link = PageData::convertLinkActionToLink(linkAction.get(), parentDoc, QRectF());
+        return PageData::convertLinkActionToLink(linkAction.get(), parentDoc, QRectF());
 
-    return link;
+    return {};
 }
 
 void AnnotationPrivate::addAnnotationToPage(::Page *pdfPage, DocumentData *doc, const Annotation *ann)
@@ -1381,22 +1379,22 @@ Annotation::RevType Annotation::revisionType() const
     return Annotation::None;
 }
 
-QList<Annotation *> Annotation::revisions() const
+std::vector<std::unique_ptr<Annotation>> Annotation::revisions() const
 {
     Q_D(const Annotation);
 
     if (!d->pdfAnnot) {
         /* Return aliases, whose ownership goes to the caller */
-        QList<Annotation *> res;
+        std::vector<std::unique_ptr<Annotation>> res;
         foreach (Annotation *rev, d->revisions)
-            res.append(rev->d_ptr->makeAlias());
+            res.push_back(std::unique_ptr<Annotation>(rev->d_ptr->makeAlias()));
         return res;
     }
 
     /* If the annotation doesn't live in a object on its own (eg bug51361), it
      * has no ref, therefore it can't have revisions */
     if (!d->pdfAnnot->getHasRef())
-        return QList<Annotation *>();
+        return std::vector<std::unique_ptr<Annotation>>();
 
     return AnnotationPrivate::findAnnotations(d->pdfPage, d->parentDoc, QSet<Annotation::SubType>(), d->pdfAnnot->getId());
 }
@@ -2712,17 +2710,14 @@ public:
     Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override;
 
     // data fields
-    Link *linkDestination;
+    std::unique_ptr<Link> linkDestination;
     LinkAnnotation::HighlightMode linkHLMode;
     QPointF linkRegion[4];
 };
 
-LinkAnnotationPrivate::LinkAnnotationPrivate() : AnnotationPrivate(), linkDestination(nullptr), linkHLMode(LinkAnnotation::Invert) { }
+LinkAnnotationPrivate::LinkAnnotationPrivate() : AnnotationPrivate(), linkHLMode(LinkAnnotation::Invert) { }
 
-LinkAnnotationPrivate::~LinkAnnotationPrivate()
-{
-    delete linkDestination;
-}
+LinkAnnotationPrivate::~LinkAnnotationPrivate() { }
 
 Annotation *LinkAnnotationPrivate::makeAlias()
 {
@@ -2748,14 +2743,13 @@ Annotation::SubType LinkAnnotation::subType() const
 Link *LinkAnnotation::linkDestination() const
 {
     Q_D(const LinkAnnotation);
-    return d->linkDestination;
+    return d->linkDestination.get();
 }
 
-void LinkAnnotation::setLinkDestination(Link *link)
+void LinkAnnotation::setLinkDestination(std::unique_ptr<Link> &&link)
 {
     Q_D(LinkAnnotation);
-    delete d->linkDestination;
-    d->linkDestination = link;
+    d->linkDestination = std::move(link);
 }
 
 LinkAnnotation::HighlightMode LinkAnnotation::linkHighlightMode() const
@@ -3127,7 +3121,7 @@ void ScreenAnnotation::setScreenTitle(const QString &title)
     d->title = title;
 }
 
-Link *ScreenAnnotation::additionalAction(AdditionalActionType type) const
+std::unique_ptr<Link> ScreenAnnotation::additionalAction(AdditionalActionType type) const
 {
     Q_D(const ScreenAnnotation);
     return d->additionalAction(type);
@@ -3162,7 +3156,7 @@ Annotation::SubType WidgetAnnotation::subType() const
     return AWidget;
 }
 
-Link *WidgetAnnotation::additionalAction(AdditionalActionType type) const
+std::unique_ptr<Link> WidgetAnnotation::additionalAction(AdditionalActionType type) const
 {
     Q_D(const WidgetAnnotation);
     return d->additionalAction(type);
diff --git a/qt6/src/poppler-annotation.h b/qt6/src/poppler-annotation.h
index 857b0f19..1e82314e 100644
--- a/qt6/src/poppler-annotation.h
+++ b/qt6/src/poppler-annotation.h
@@ -368,11 +368,8 @@ public:
 
     /**
      * Returns the revisions of this annotation
-     *
-     * \note The caller owns the returned annotations and they should
-     *       be deleted when no longer required.
      */
-    QList<Annotation *> revisions() const;
+    std::vector<std::unique_ptr<Annotation>> revisions() const;
 
     /**
      * The type of the annotation.
@@ -763,7 +760,7 @@ public:
     };
 
     Link *linkDestination() const;
-    void setLinkDestination(Link *link);
+    void setLinkDestination(std::unique_ptr<Link> &&link);
 
     HighlightMode linkHighlightMode() const;
     void setLinkHighlightMode(HighlightMode mode);
@@ -967,10 +964,10 @@ public:
     void setScreenTitle(const QString &title);
 
     /**
-     * Returns the additional action of the given @p type fo the annotation or
+     * Returns the additional action of the given @p type for the annotation or
      * @c 0 if no action has been defined.
      */
-    Link *additionalAction(AdditionalActionType type) const;
+    std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
 
 private:
     ScreenAnnotation();
@@ -997,10 +994,10 @@ public:
     SubType subType() const override;
 
     /**
-     * Returns the additional action of the given @p type fo the annotation or
+     * Returns the additional action of the given @p type for the annotation or
      * @c 0 if no action has been defined.
      */
-    Link *additionalAction(AdditionalActionType type) const;
+    std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
 
 private:
     WidgetAnnotation();
diff --git a/qt6/src/poppler-document.cc b/qt6/src/poppler-document.cc
index 66817c1b..ec8b290c 100644
--- a/qt6/src/poppler-document.cc
+++ b/qt6/src/poppler-document.cc
@@ -64,30 +64,29 @@
 
 namespace Poppler {
 
-Document *Document::load(const QString &filePath, const QByteArray &ownerPassword, const QByteArray &userPassword)
+std::unique_ptr<Document> Document::load(const QString &filePath, const QByteArray &ownerPassword, const QByteArray &userPassword)
 {
     DocumentData *doc = new DocumentData(filePath, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
     return DocumentData::checkDocument(doc);
 }
 
-Document *Document::load(QIODevice *device, const QByteArray &ownerPassword, const QByteArray &userPassword)
+std::unique_ptr<Document> Document::load(QIODevice *device, const QByteArray &ownerPassword, const QByteArray &userPassword)
 {
     DocumentData *doc = new DocumentData(device, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
     return DocumentData::checkDocument(doc);
 }
 
-Document *Document::loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword, const QByteArray &userPassword)
+std::unique_ptr<Document> Document::loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword, const QByteArray &userPassword)
 {
     // create stream
     DocumentData *doc = new DocumentData(fileContents, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
     return DocumentData::checkDocument(doc);
 }
 
-Document *DocumentData::checkDocument(DocumentData *doc)
+std::unique_ptr<Document> DocumentData::checkDocument(DocumentData *doc)
 {
-    Document *pdoc;
     if (doc->doc->isOk() || doc->doc->getErrorCode() == errEncrypted) {
-        pdoc = new Document(doc);
+        auto pdoc = std::unique_ptr<Document>(new Document(doc));
         if (doc->doc->getErrorCode() == errEncrypted)
             pdoc->m_doc->locked = true;
         else {
@@ -111,12 +110,12 @@ Document::~Document()
     delete m_doc;
 }
 
-Page *Document::page(int index) const
+std::unique_ptr<Page> Document::page(int index) const
 {
-    Page *page = new Page(m_doc, index);
+    // Cannot call std::make_unique, because the constructor of Page is private
+    auto page = std::unique_ptr<Page>(new Page(m_doc, index));
     if (page->m_page->page == nullptr) {
-        delete page;
-        return nullptr;
+        page.reset();
     }
 
     return page;
@@ -228,9 +227,10 @@ QList<EmbeddedFile *> Document::embeddedFiles() const
     return m_doc->m_embeddedFiles;
 }
 
-FontIterator *Document::newFontIterator(int startPage) const
+std::unique_ptr<FontIterator> Document::newFontIterator(int startPage) const
 {
-    return new FontIterator(startPage, m_doc);
+    // Cannot use std::make_unique, because the FontIterator constructor is private
+    return std::unique_ptr<FontIterator>(new FontIterator(startPage, m_doc));
 }
 
 QByteArray Document::fontData(const FontInfo &fi) const
@@ -555,7 +555,7 @@ void Document::getPdfVersion(int *major, int *minor) const
         *minor = m_doc->doc->getPDFMinorVersion();
 }
 
-Page *Document::page(const QString &label) const
+std::unique_ptr<Page> Document::page(const QString &label) const
 {
     GooString label_g(label.toLatin1().data());
     int index;
@@ -590,11 +590,11 @@ QVector<OutlineItem> Document::outline() const
     return result;
 }
 
-LinkDestination *Document::linkDestination(const QString &name)
+std::unique_ptr<LinkDestination> Document::linkDestination(const QString &name)
 {
     GooString *namedDest = QStringToGooString(name);
     LinkDestinationData ldd(nullptr, namedDest, m_doc, false);
-    LinkDestination *ld = new LinkDestination(ldd);
+    auto ld = std::make_unique<LinkDestination>(ldd);
     delete namedDest;
     return ld;
 }
@@ -701,14 +701,16 @@ Document::RenderHints Document::renderHints() const
     return Document::RenderHints(m_doc->m_hints);
 }
 
-PSConverter *Document::psConverter() const
+std::unique_ptr<PSConverter> Document::psConverter() const
 {
-    return new PSConverter(m_doc);
+    // Cannot use std::make_unique, because the PSConverter constructor is private
+    return std::unique_ptr<PSConverter>(new PSConverter(m_doc));
 }
 
-PDFConverter *Document::pdfConverter() const
+std::unique_ptr<PDFConverter> Document::pdfConverter() const
 {
-    return new PDFConverter(m_doc);
+    // Cannot use std::make_unique, because the PDFConverter constructor is private
+    return std::unique_ptr<PDFConverter>(new PDFConverter(m_doc));
 }
 
 QString Document::metadata() const
@@ -801,16 +803,16 @@ QVector<int> Document::formCalculateOrder() const
     return result;
 }
 
-QVector<FormFieldSignature *> Document::signatures() const
+std::vector<std::unique_ptr<FormFieldSignature>> Document::signatures() const
 {
-    QVector<FormFieldSignature *> result;
+    std::vector<std::unique_ptr<FormFieldSignature>> result;
 
     const std::vector<::FormFieldSignature *> pSignatures = m_doc->doc->getSignatureFields();
 
     for (::FormFieldSignature *pSignature : pSignatures) {
         ::FormWidget *fw = pSignature->getCreateWidget();
         ::Page *p = m_doc->doc->getPage(fw->getWidgetAnnotation()->getPageNum());
-        result.append(new FormFieldSignature(m_doc, p, static_cast<FormWidgetSignature *>(fw)));
+        result.push_back(std::make_unique<FormFieldSignature>(m_doc, p, static_cast<FormWidgetSignature *>(fw)));
     }
 
     return result;
diff --git a/qt6/src/poppler-form.cc b/qt6/src/poppler-form.cc
index f70cea84..0c3f3b8c 100644
--- a/qt6/src/poppler-form.cc
+++ b/qt6/src/poppler-form.cc
@@ -8,7 +8,7 @@
  * Copyright (C) 2018, Andre Heinecke <aheinecke at intevation.de>
  * Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
  * Copyright (C) 2018 Chinmoy Ranjan Pradhan <chinmoyrp65 at protonmail.com>
- * Copyright (C) 2018, 2020 Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2018, 2020, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2019 João Netto <joaonetto901 at gmail.com>
  * Copyright (C) 2020 David García Garzón <voki at canvoki.net>
  * Copyright (C) 2020 Thorsten Behrens <Thorsten.Behrens at CIB.de>
@@ -221,16 +221,16 @@ void FormField::setPrintable(bool value)
     m_formData->fm->getWidgetAnnotation()->setFlags(flags);
 }
 
-Link *FormField::activationAction() const
+std::unique_ptr<Link> FormField::activationAction() const
 {
-    Link *action = nullptr;
     if (::LinkAction *act = m_formData->fm->getActivationAction()) {
-        action = PageData::convertLinkActionToLink(act, m_formData->doc, QRectF());
+        return PageData::convertLinkActionToLink(act, m_formData->doc, QRectF());
     }
-    return action;
+
+    return {};
 }
 
-Link *FormField::additionalAction(AdditionalActionType type) const
+std::unique_ptr<Link> FormField::additionalAction(AdditionalActionType type) const
 {
     Annot::FormAdditionalActionsType actionType = Annot::actionFieldModified;
     switch (type) {
@@ -248,27 +248,27 @@ Link *FormField::additionalAction(AdditionalActionType type) const
         break;
     }
 
-    Link *action = nullptr;
     if (std::unique_ptr<::LinkAction> act = m_formData->fm->getAdditionalAction(actionType)) {
-        action = PageData::convertLinkActionToLink(act.get(), m_formData->doc, QRectF());
+        return PageData::convertLinkActionToLink(act.get(), m_formData->doc, QRectF());
     }
-    return action;
+
+    return {};
 }
 
-Link *FormField::additionalAction(Annotation::AdditionalActionType type) const
+std::unique_ptr<Link> FormField::additionalAction(Annotation::AdditionalActionType type) const
 {
     ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation();
     if (!w) {
-        return nullptr;
+        return {};
     }
 
     const Annot::AdditionalActionsType actionType = toPopplerAdditionalActionType(type);
 
-    Link *action = nullptr;
     if (std::unique_ptr<::LinkAction> act = w->getAdditionalAction(actionType)) {
-        action = PageData::convertLinkActionToLink(act.get(), m_formData->doc, QRectF());
+        return PageData::convertLinkActionToLink(act.get(), m_formData->doc, QRectF());
     }
-    return action;
+
+    return {};
 }
 
 FormFieldButton::FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w) : FormField(std::make_unique<FormFieldData>(doc, p, w)) { }
diff --git a/qt6/src/poppler-form.h b/qt6/src/poppler-form.h
index 9dbc6699..468689e6 100644
--- a/qt6/src/poppler-form.h
+++ b/qt6/src/poppler-form.h
@@ -7,7 +7,7 @@
  * Copyright (C) 2017, Tobias C. Berner <tcberner at freebsd.org>
  * Copyright (C) 2018, Andre Heinecke <aheinecke at intevation.de>
  * Copyright (C) 2018, Chinmoy Ranjan Pradhan <chinmoyrp65 at protonmail.com>
- * Copyright (C) 2018, Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2018, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2019 João Netto <joaonetto901 at gmail.com>
  * Copyright (C) 2019, Adrian Johnson <ajohnson at redneon.com>
  * Copyright (C) 2020, Thorsten Behrens <Thorsten.Behrens at CIB.de>
@@ -172,7 +172,7 @@ public:
 
       \note It may be null.
      */
-    Link *activationAction() const;
+    std::unique_ptr<Link> activationAction() const;
 
     /**
      * Describes the flags from the form 'AA' dictionary.
@@ -187,12 +187,12 @@ public:
     /**
      * Returns a given form additional action
      */
-    Link *additionalAction(AdditionalActionType type) const;
+    std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
 
     /**
      * Returns a given widget annotation additional action
      */
-    Link *additionalAction(Annotation::AdditionalActionType type) const;
+    std::unique_ptr<Link> additionalAction(Annotation::AdditionalActionType type) const;
 
 protected:
     /// \cond PRIVATE
diff --git a/qt6/src/poppler-link-extractor-private.h b/qt6/src/poppler-link-extractor-private.h
index a3cd7f8d..e2cc78b2 100644
--- a/qt6/src/poppler-link-extractor-private.h
+++ b/qt6/src/poppler-link-extractor-private.h
@@ -1,5 +1,6 @@
 /* poppler-link-extractor_p.h: qt interface to poppler
  * Copyright (C) 2007, 2008, 2011, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2021, Oliver Sander <oliver.sander at tu-dresden.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +20,9 @@
 #ifndef _POPPLER_LINK_EXTRACTOR_H_
 #define _POPPLER_LINK_EXTRACTOR_H_
 
+#include <memory>
+#include <vector>
+
 #include <Object.h>
 #include <OutputDev.h>
 
@@ -42,13 +46,13 @@ public:
     void processLink(::AnnotLink *link) override;
 
     // our stuff
-    QList<Link *> links();
+    std::vector<std::unique_ptr<Link>> links();
 
 private:
     PageData *m_data;
     double m_pageCropWidth;
     double m_pageCropHeight;
-    QList<Link *> m_links;
+    std::vector<std::unique_ptr<Link>> m_links;
 };
 
 }
diff --git a/qt6/src/poppler-link-extractor.cc b/qt6/src/poppler-link-extractor.cc
index 7fe05f27..e883ee53 100644
--- a/qt6/src/poppler-link-extractor.cc
+++ b/qt6/src/poppler-link-extractor.cc
@@ -1,6 +1,7 @@
 /* poppler-link-extractor_p.h: qt interface to poppler
  * Copyright (C) 2007, 2008, 2011, Pino Toscano <pino at kde.org>
  * Copyright (C) 2008, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2021, Oliver Sander <oliver.sander at tu-dresden.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,10 +43,7 @@ LinkExtractorOutputDev::LinkExtractorOutputDev(PageData *data) : m_data(data)
     setDefaultCTM(gfxState.getCTM());
 }
 
-LinkExtractorOutputDev::~LinkExtractorOutputDev()
-{
-    qDeleteAll(m_links);
-}
+LinkExtractorOutputDev::~LinkExtractorOutputDev() { }
 
 void LinkExtractorOutputDev::processLink(::AnnotLink *link)
 {
@@ -64,18 +62,16 @@ void LinkExtractorOutputDev::processLink(::AnnotLink *link)
     linkArea.setRight((double)rightAux / m_pageCropWidth);
     linkArea.setBottom((double)bottomAux / m_pageCropHeight);
 
-    Link *popplerLink = m_data->convertLinkActionToLink(link->getAction(), linkArea);
+    std::unique_ptr<Link> popplerLink = m_data->convertLinkActionToLink(link->getAction(), linkArea);
     if (popplerLink) {
-        m_links.append(popplerLink);
+        m_links.push_back(std::move(popplerLink));
     }
     OutputDev::processLink(link);
 }
 
-QList<Link *> LinkExtractorOutputDev::links()
+std::vector<std::unique_ptr<Link>> LinkExtractorOutputDev::links()
 {
-    QList<Link *> ret = m_links;
-    m_links.clear();
-    return ret;
+    return std::move(m_links);
 }
 
 }
diff --git a/qt6/src/poppler-link-private.h b/qt6/src/poppler-link-private.h
index 6a868722..3776c593 100644
--- a/qt6/src/poppler-link-private.h
+++ b/qt6/src/poppler-link-private.h
@@ -44,7 +44,7 @@ public:
     LinkPrivate &operator=(const LinkPrivate &) = delete;
 
     QRectF linkArea;
-    QVector<Link *> nextLinks;
+    std::vector<std::unique_ptr<Link>> nextLinks;
 };
 
 class LinkOCGStatePrivate : public LinkPrivate
diff --git a/qt6/src/poppler-link.cc b/qt6/src/poppler-link.cc
index 7dd82b42..177173af 100644
--- a/qt6/src/poppler-link.cc
+++ b/qt6/src/poppler-link.cc
@@ -6,7 +6,7 @@
  * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
  * Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
  * Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
- * Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2020, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -69,10 +69,7 @@ LinkDestinationPrivate::LinkDestinationPrivate()
     changeZoom = false;
 }
 
-LinkPrivate::~LinkPrivate()
-{
-    qDeleteAll(nextLinks);
-}
+LinkPrivate::~LinkPrivate() = default;
 
 LinkOCGStatePrivate::~LinkOCGStatePrivate() = default;
 
@@ -420,7 +417,12 @@ QRectF Link::linkArea() const
 
 QVector<Link *> Link::nextLinks() const
 {
-    return d_ptr->nextLinks;
+    QVector<Link *> links(d_ptr->nextLinks.size());
+    for (std::size_t i = 0; i < links.size(); i++) {
+        links[i] = d_ptr->nextLinks[i].get();
+    }
+
+    return links;
 }
 
 // LinkGoto
diff --git a/qt6/src/poppler-link.h b/qt6/src/poppler-link.h
index ae65ce75..595916fd 100644
--- a/qt6/src/poppler-link.h
+++ b/qt6/src/poppler-link.h
@@ -5,7 +5,7 @@
  * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  * Copyright (C) 2013, Anthony Granger <grangeranthony at gmail.com>
  * Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
- * Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2020, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -221,6 +221,8 @@ public:
 
     /**
      * Get the next links to be activated / executed after this link.
+     *
+     * \note The caller does not get ownership of the returned objects.
      */
     QVector<Link *> nextLinks() const;
 
diff --git a/qt6/src/poppler-page-private.h b/qt6/src/poppler-page-private.h
index 855efbff..5058ec61 100644
--- a/qt6/src/poppler-page-private.h
+++ b/qt6/src/poppler-page-private.h
@@ -39,14 +39,14 @@ class PageTransition;
 class PageData
 {
 public:
-    Link *convertLinkActionToLink(::LinkAction *a, const QRectF &linkArea);
+    std::unique_ptr<Link> convertLinkActionToLink(::LinkAction *a, const QRectF &linkArea);
 
     DocumentData *parentDoc;
     ::Page *page;
     int index;
     PageTransition *transition;
 
-    static Link *convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc, const QRectF &linkArea);
+    static std::unique_ptr<Link> convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc, const QRectF &linkArea);
 
     TextPage *prepareTextSearch(const QString &text, Page::Rotation rotate, QVector<Unicode> *u);
     bool performSingleTextSearch(TextPage *textPage, QVector<Unicode> &u, double &sLeft, double &sTop, double &sRight, double &sBottom, Page::SearchDirection direction, bool sCase, bool sWords, bool sDiacritics, bool sAcrossLines);
diff --git a/qt6/src/poppler-page.cc b/qt6/src/poppler-page.cc
index c561377d..a0f18908 100644
--- a/qt6/src/poppler-page.cc
+++ b/qt6/src/poppler-page.cc
@@ -23,7 +23,7 @@
  * Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
  * Copyright (C) 2018, Tobias Deiminger <haxtibal at posteo.de>
  * Copyright (C) 2018, 2021 Nelson Benítez León <nbenitezl at gmail.com>
- * Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2020, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2020 Philipp Knechtges <philipp-dev at knechtges.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -193,23 +193,23 @@ private:
 
 QImageDumpingQPainterOutputDev::~QImageDumpingQPainterOutputDev() = default;
 
-Link *PageData::convertLinkActionToLink(::LinkAction *a, const QRectF &linkArea)
+std::unique_ptr<Link> PageData::convertLinkActionToLink(::LinkAction *a, const QRectF &linkArea)
 {
     return convertLinkActionToLink(a, parentDoc, linkArea);
 }
 
-Link *PageData::convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc, const QRectF &linkArea)
+std::unique_ptr<Link> PageData::convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc, const QRectF &linkArea)
 {
     if (!a)
         return nullptr;
 
-    Link *popplerLink = nullptr;
+    std::unique_ptr<Link> popplerLink;
     switch (a->getKind()) {
     case actionGoTo: {
         LinkGoTo *g = (LinkGoTo *)a;
         const LinkDestinationData ldd(g->getDest(), g->getNamedDest(), parentDoc, false);
         // create link: no ext file, namedDest, object pointer
-        popplerLink = new LinkGoto(linkArea, QString(), LinkDestination(ldd));
+        popplerLink = std::make_unique<LinkGoto>(linkArea, QString(), LinkDestination(ldd));
     } break;
 
     case actionGoToR: {
@@ -218,61 +218,61 @@ Link *PageData::convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc
         const QString fileName = UnicodeParsedString(g->getFileName());
         const LinkDestinationData ldd(g->getDest(), g->getNamedDest(), parentDoc, !fileName.isEmpty());
         // create link: fileName, namedDest, object pointer
-        popplerLink = new LinkGoto(linkArea, fileName, LinkDestination(ldd));
+        popplerLink = std::make_unique<LinkGoto>(linkArea, fileName, LinkDestination(ldd));
     } break;
 
     case actionLaunch: {
         LinkLaunch *e = (LinkLaunch *)a;
         const GooString *p = e->getParams();
-        popplerLink = new LinkExecute(linkArea, e->getFileName()->c_str(), p ? p->c_str() : nullptr);
+        popplerLink = std::make_unique<LinkExecute>(linkArea, e->getFileName()->c_str(), p ? p->c_str() : nullptr);
     } break;
 
     case actionNamed: {
         const std::string &name = ((LinkNamed *)a)->getName();
         if (name == "NextPage")
-            popplerLink = new LinkAction(linkArea, LinkAction::PageNext);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::PageNext);
         else if (name == "PrevPage")
-            popplerLink = new LinkAction(linkArea, LinkAction::PagePrev);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::PagePrev);
         else if (name == "FirstPage")
-            popplerLink = new LinkAction(linkArea, LinkAction::PageFirst);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::PageFirst);
         else if (name == "LastPage")
-            popplerLink = new LinkAction(linkArea, LinkAction::PageLast);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::PageLast);
         else if (name == "GoBack")
-            popplerLink = new LinkAction(linkArea, LinkAction::HistoryBack);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::HistoryBack);
         else if (name == "GoForward")
-            popplerLink = new LinkAction(linkArea, LinkAction::HistoryForward);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::HistoryForward);
         else if (name == "Quit")
-            popplerLink = new LinkAction(linkArea, LinkAction::Quit);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::Quit);
         else if (name == "GoToPage")
-            popplerLink = new LinkAction(linkArea, LinkAction::GoToPage);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::GoToPage);
         else if (name == "Find")
-            popplerLink = new LinkAction(linkArea, LinkAction::Find);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::Find);
         else if (name == "FullScreen")
-            popplerLink = new LinkAction(linkArea, LinkAction::Presentation);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::Presentation);
         else if (name == "Print")
-            popplerLink = new LinkAction(linkArea, LinkAction::Print);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::Print);
         else if (name == "Close") {
-            // acroread closes the document always, doesnt care whether
+            // acroread closes the document always, doesn't care whether
             // its presentation mode or not
-            // popplerLink = new LinkAction( linkArea, LinkAction::EndPresentation );
-            popplerLink = new LinkAction(linkArea, LinkAction::Close);
+            // popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::EndPresentation);
+            popplerLink = std::make_unique<LinkAction>(linkArea, LinkAction::Close);
         } else {
             // TODO
         }
     } break;
 
     case actionURI: {
-        popplerLink = new LinkBrowse(linkArea, ((LinkURI *)a)->getURI().c_str());
+        popplerLink = std::make_unique<LinkBrowse>(linkArea, ((LinkURI *)a)->getURI().c_str());
     } break;
 
     case actionSound: {
         ::LinkSound *ls = (::LinkSound *)a;
-        popplerLink = new LinkSound(linkArea, ls->getVolume(), ls->getSynchronous(), ls->getRepeat(), ls->getMix(), new SoundObject(ls->getSound()));
+        popplerLink = std::make_unique<LinkSound>(linkArea, ls->getVolume(), ls->getSynchronous(), ls->getRepeat(), ls->getMix(), new SoundObject(ls->getSound()));
     } break;
 
     case actionJavaScript: {
         ::LinkJavaScript *ljs = (::LinkJavaScript *)a;
-        popplerLink = new LinkJavaScript(linkArea, UnicodeParsedString(ljs->getScript()));
+        popplerLink = std::make_unique<LinkJavaScript>(linkArea, UnicodeParsedString(ljs->getScript()));
     } break;
 
     case actionMovie: {
@@ -300,7 +300,7 @@ Link *PageData::convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc
             break;
         };
 
-        popplerLink = new LinkMovie(linkArea, operation, title, reference);
+        popplerLink = std::make_unique<LinkMovie>(linkArea, operation, title, reference);
     } break;
 
     case actionRendition: {
@@ -310,21 +310,21 @@ Link *PageData::convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc
         if (lrn->hasScreenAnnot())
             reference = lrn->getScreenAnnot();
 
-        popplerLink = new LinkRendition(linkArea, lrn->getMedia() ? lrn->getMedia()->copy() : nullptr, lrn->getOperation(), UnicodeParsedString(lrn->getScript()), reference);
+        popplerLink = std::make_unique<LinkRendition>(linkArea, lrn->getMedia() ? lrn->getMedia()->copy() : nullptr, lrn->getOperation(), UnicodeParsedString(lrn->getScript()), reference);
     } break;
 
     case actionOCGState: {
         ::LinkOCGState *plocg = (::LinkOCGState *)a;
 
         LinkOCGStatePrivate *locgp = new LinkOCGStatePrivate(linkArea, plocg->getStateList(), plocg->getPreserveRB());
-        popplerLink = new LinkOCGState(locgp);
+        popplerLink = std::make_unique<LinkOCGState>(locgp);
     } break;
 
     case actionHide: {
         ::LinkHide *lh = (::LinkHide *)a;
 
         LinkHidePrivate *lhp = new LinkHidePrivate(linkArea, lh->hasTargetName() ? UnicodeParsedString(lh->getTargetName()) : QString(), lh->isShowAction());
-        popplerLink = new LinkHide(lhp);
+        popplerLink = std::make_unique<LinkHide>(lhp);
     } break;
 
     case actionResetForm:
@@ -336,11 +336,11 @@ Link *PageData::convertLinkActionToLink(::LinkAction *a, DocumentData *parentDoc
     }
 
     if (popplerLink) {
-        QVector<Link *> links;
+        std::vector<std::unique_ptr<Link>> links;
         for (const std::unique_ptr<::LinkAction> &nextAction : a->nextActions()) {
-            links << convertLinkActionToLink(nextAction.get(), parentDoc, linkArea);
+            links.push_back(convertLinkActionToLink(nextAction.get(), parentDoc, linkArea));
         }
-        LinkPrivate::get(popplerLink)->nextLinks = links;
+        LinkPrivate::get(popplerLink.get())->nextLinks = std::move(links);
     }
 
     return popplerLink;
@@ -691,16 +691,16 @@ QList<QRectF> Page::search(const QString &text, SearchFlags flags, Rotation rota
     return results;
 }
 
-QList<TextBox *> Page::textList(Rotation rotate) const
+std::vector<std::unique_ptr<TextBox>> Page::textList(Rotation rotate) const
 {
     return textList(rotate, nullptr, QVariant());
 }
 
-QList<TextBox *> Page::textList(Rotation rotate, ShouldAbortQueryFunc shouldAbortExtractionCallback, const QVariant &closure) const
+std::vector<std::unique_ptr<TextBox>> Page::textList(Rotation rotate, ShouldAbortQueryFunc shouldAbortExtractionCallback, const QVariant &closure) const
 {
     TextOutputDev *output_dev;
 
-    QList<TextBox *> output_list;
+    std::vector<std::unique_ptr<TextBox>> output_list;
 
     output_dev = new TextOutputDev(nullptr, false, 0, false, false);
 
@@ -729,7 +729,7 @@ QList<TextBox *> Page::textList(Rotation rotate, ShouldAbortQueryFunc shouldAbor
         double xMin, yMin, xMax, yMax;
         word->getBBox(&xMin, &yMin, &xMax, &yMax);
 
-        TextBox *text_box = new TextBox(string, QRectF(xMin, yMin, xMax - xMin, yMax - yMin));
+        auto text_box = std::make_unique<TextBox>(string, QRectF(xMin, yMin, xMax - xMin, yMax - yMin));
         text_box->m_data->hasSpaceAfter = word->hasSpaceAfter() == true;
         text_box->m_data->charBBoxes.reserve(word->getLength());
         for (int j = 0; j < word->getLength(); ++j) {
@@ -737,9 +737,9 @@ QList<TextBox *> Page::textList(Rotation rotate, ShouldAbortQueryFunc shouldAbor
             text_box->m_data->charBBoxes.append(QRectF(xMin, yMin, xMax - xMin, yMax - yMin));
         }
 
-        wordBoxMap.insert(word, text_box);
+        wordBoxMap.insert(word, text_box.get());
 
-        output_list.append(text_box);
+        output_list.push_back(std::move(text_box));
     }
 
     for (int i = 0; i < word_list->getLength(); i++) {
@@ -766,7 +766,7 @@ PageTransition *Page::transition() const
     return m_page->transition;
 }
 
-Link *Page::action(PageAction act) const
+std::unique_ptr<Link> Page::action(PageAction act) const
 {
     if (act == Page::Opening || act == Page::Closing) {
         Object o = m_page->page->getActions();
@@ -777,11 +777,9 @@ Link *Page::action(PageAction act) const
         const char *key = act == Page::Opening ? "O" : "C";
         Object o2 = dict->lookup((char *)key);
         std::unique_ptr<::LinkAction> lact = ::LinkAction::parseAction(&o2, m_page->parentDoc->doc->getCatalog()->getBaseURI());
-        Link *popplerLink = nullptr;
         if (lact != nullptr) {
-            popplerLink = m_page->convertLinkActionToLink(lact.get(), QRectF());
+            return m_page->convertLinkActionToLink(lact.get(), QRectF());
         }
-        return popplerLink;
     }
     return nullptr;
 }
@@ -824,21 +822,19 @@ void Page::defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool up
     m_page->page->getDefaultCTM(CTM, dpiX, dpiY, rotate, false, upsideDown);
 }
 
-QList<Link *> Page::links() const
+std::vector<std::unique_ptr<Link>> Page::links() const
 {
     LinkExtractorOutputDev link_dev(m_page);
     m_page->parentDoc->doc->processLinks(&link_dev, m_page->index + 1);
-    QList<Link *> popplerLinks = link_dev.links();
-
-    return popplerLinks;
+    return link_dev.links();
 }
 
-QList<Annotation *> Page::annotations() const
+std::vector<std::unique_ptr<Annotation>> Page::annotations() const
 {
     return AnnotationPrivate::findAnnotations(m_page->page, m_page->parentDoc, QSet<Annotation::SubType>());
 }
 
-QList<Annotation *> Page::annotations(const QSet<Annotation::SubType> &subtypes) const
+std::vector<std::unique_ptr<Annotation>> Page::annotations(const QSet<Annotation::SubType> &subtypes) const
 {
     return AnnotationPrivate::findAnnotations(m_page->page, m_page->parentDoc, subtypes);
 }
@@ -853,37 +849,37 @@ void Page::removeAnnotation(const Annotation *ann)
     AnnotationPrivate::removeAnnotationFromPage(m_page->page, ann);
 }
 
-QList<FormField *> Page::formFields() const
+std::vector<std::unique_ptr<FormField>> Page::formFields() const
 {
-    QList<FormField *> fields;
+    std::vector<std::unique_ptr<FormField>> fields;
     ::Page *p = m_page->page;
     const std::unique_ptr<FormPageWidgets> form = p->getFormWidgets();
     int formcount = form->getNumWidgets();
     for (int i = 0; i < formcount; ++i) {
         ::FormWidget *fm = form->getWidget(i);
-        FormField *ff = nullptr;
+        std::unique_ptr<FormField> ff;
         switch (fm->getType()) {
         case formButton: {
-            ff = new FormFieldButton(m_page->parentDoc, p, static_cast<FormWidgetButton *>(fm));
+            ff = std::make_unique<FormFieldButton>(m_page->parentDoc, p, static_cast<FormWidgetButton *>(fm));
         } break;
 
         case formText: {
-            ff = new FormFieldText(m_page->parentDoc, p, static_cast<FormWidgetText *>(fm));
+            ff = std::make_unique<FormFieldText>(m_page->parentDoc, p, static_cast<FormWidgetText *>(fm));
         } break;
 
         case formChoice: {
-            ff = new FormFieldChoice(m_page->parentDoc, p, static_cast<FormWidgetChoice *>(fm));
+            ff = std::make_unique<FormFieldChoice>(m_page->parentDoc, p, static_cast<FormWidgetChoice *>(fm));
         } break;
 
         case formSignature: {
-            ff = new FormFieldSignature(m_page->parentDoc, p, static_cast<FormWidgetSignature *>(fm));
+            ff = std::make_unique<FormFieldSignature>(m_page->parentDoc, p, static_cast<FormWidgetSignature *>(fm));
         } break;
 
         default:;
         }
 
         if (ff)
-            fields.append(ff);
+            fields.push_back(std::move(ff));
     }
 
     return fields;
diff --git a/qt6/src/poppler-private.h b/qt6/src/poppler-private.h
index b99b03c1..3129c6b6 100644
--- a/qt6/src/poppler-private.h
+++ b/qt6/src/poppler-private.h
@@ -167,7 +167,7 @@ public:
      */
     void noitfyXRefReconstructed();
 
-    static Document *checkDocument(DocumentData *doc);
+    static std::unique_ptr<Document> checkDocument(DocumentData *doc);
 
     PDFDoc *doc;
     QString m_filePath;
diff --git a/qt6/src/poppler-qt6.h b/qt6/src/poppler-qt6.h
index 099bc6db..bad34bc5 100644
--- a/qt6/src/poppler-qt6.h
+++ b/qt6/src/poppler-qt6.h
@@ -16,7 +16,7 @@
  * Copyright (C) 2012, 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
  * Copyright (C) 2013 Anthony Granger <grangeranthony at gmail.com>
  * Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
- * Copyright (C) 2017, 2020 Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2017, 2020, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
  * Copyright (C) 2018, 2021 Nelson Benítez León <nbenitezl at gmail.com>
  * Copyright (C) 2019 Jan Grulich <jgrulich at redhat.com>
@@ -47,6 +47,8 @@
 #define __POPPLER_QT_H__
 
 #include <functional>
+#include <memory>
+#include <vector>
 
 #include "poppler-annotation.h"
 #include "poppler-link.h"
@@ -281,13 +283,12 @@ class FontIteratorData;
 
    You can use it in the following way:
    \code
-Poppler::FontIterator* it = doc->newFontIterator();
+std::unique_ptr<Poppler::FontIterator> it = doc->newFontIterator();
 while (it->hasNext()) {
 QList<Poppler::FontInfo> fonts = it->next();
 // do something with the fonts
 }
-// after doing the job, the iterator must be freed
-delete it;
+// no need to free the iterator after doing the job
    \endcode
 */
 class POPPLER_QT6_EXPORT FontIterator
@@ -779,12 +780,9 @@ rather unexpected results.
        up-to-down), the QList contains the text in the proper
        order.
 
-       \note The caller owns the text boxes and they should
-             be deleted when no longer required.
-
        \warning This method is not tested with Asian scripts
     */
-    QList<TextBox *> textList(Rotation rotate = Rotate0) const;
+    std::vector<std::unique_ptr<TextBox>> textList(Rotation rotate = Rotate0) const;
 
     /**
        Returns a list of text of the page
@@ -803,12 +801,9 @@ rather unexpected results.
        \param closure opaque structure that will be passed
        back to shouldAbortExtractionCallback.
 
-       \note The caller owns the text boxes and they should
-             be deleted when no longer required.
-
        \warning This method is not tested with Asian scripts
     */
-    QList<TextBox *> textList(Rotation rotate, ShouldAbortQueryFunc shouldAbortExtractionCallback, const QVariant &closure) const;
+    std::vector<std::unique_ptr<TextBox>> textList(Rotation rotate, ShouldAbortQueryFunc shouldAbortExtractionCallback, const QVariant &closure) const;
 
     /**
        \return The dimensions (cropbox) of the page, in points (i.e. 1/72th of an inch)
@@ -833,9 +828,9 @@ rather unexpected results.
     PageTransition *transition() const;
 
     /**
-      Gets the page action specified, or NULL if there is no action.
+      Gets the page action specified, or empty unique pointer if there is no action.
     **/
-    Link *action(PageAction act) const;
+    std::unique_ptr<Link> action(PageAction act) const;
 
     /**
        Types of orientations that are possible
@@ -861,17 +856,15 @@ rather unexpected results.
     /**
       Gets the links of the page
     */
-    QList<Link *> links() const;
+    std::vector<std::unique_ptr<Link>> links() const;
 
     /**
      Returns the annotations of the page
 
      \note If you call this method twice, you get different objects
            pointing to the same annotations (see Annotation).
-           The caller owns the returned objects and they should be deleted
-           when no longer required.
     */
-    QList<Annotation *> annotations() const;
+    std::vector<std::unique_ptr<Annotation>> annotations() const;
 
     /**
             Returns the annotations of the page
@@ -880,10 +873,8 @@ rather unexpected results.
 
             \note If you call this method twice, you get different objects
                   pointing to the same annotations (see Annotation).
-                  The caller owns the returned objects and they should be deleted
-                  when no longer required.
     */
-    QList<Annotation *> annotations(const QSet<Annotation::SubType> &subtypes) const;
+    std::vector<std::unique_ptr<Annotation>> annotations(const QSet<Annotation::SubType> &subtypes) const;
 
     /**
      Adds an annotation to the page
@@ -902,9 +893,8 @@ rather unexpected results.
 
     /**
      Returns the form fields on the page
-     The caller gets the ownership of the returned objects.
     */
-    QList<FormField *> formFields() const;
+    std::vector<std::unique_ptr<FormField>> formFields() const;
 
     /**
      Returns the page duration. That is the time, in seconds, that the page
@@ -1016,7 +1006,7 @@ private:
    \section ownership Ownership of the returned objects
 
    All the functions that returns class pointers create new object, and the
-   responsibility of those is given to the callee.
+   responsibility of those is given to the caller.
 
    The only exception is \link Poppler::Page::transition() Page::transition()\endlink.
 
@@ -1173,15 +1163,12 @@ public:
        \param userPassword the Latin1-encoded user ("open") password
        to use in loading the file
 
-       \return the loaded document, or NULL on error
-
-       \note The caller owns the pointer to Document, and this should
-       be deleted when no longer required.
+       \return the loaded document, or empty unique pointer on error
 
        \warning The returning document may be locked if a password is required
        to open the file, and one is not provided (as the userPassword).
     */
-    static Document *load(const QString &filePath, const QByteArray &ownerPassword = QByteArray(), const QByteArray &userPassword = QByteArray());
+    static std::unique_ptr<Document> load(const QString &filePath, const QByteArray &ownerPassword = QByteArray(), const QByteArray &userPassword = QByteArray());
 
     /**
        Load the document from a device
@@ -1192,12 +1179,7 @@ public:
        \param userPassword the Latin1-encoded user ("open") password
        to use in loading the file
 
-       \return the loaded document, or NULL on error
-
-       \note The caller owns the pointer to Document, and this should
-       be deleted when no longer required.
-
-       \note The ownership of the device stays with the caller.
+       \return the loaded document, or empty unique pointer on error
 
        \note if the file is on disk it is recommended to use the other load overload
        since it is less resource intensive
@@ -1205,7 +1187,7 @@ public:
        \warning The returning document may be locked if a password is required
        to open the file, and one is not provided (as the userPassword).
     */
-    static Document *load(QIODevice *device, const QByteArray &ownerPassword = QByteArray(), const QByteArray &userPassword = QByteArray());
+    static std::unique_ptr<Document> load(QIODevice *device, const QByteArray &ownerPassword = QByteArray(), const QByteArray &userPassword = QByteArray());
 
     /**
        Load the document from memory
@@ -1218,15 +1200,12 @@ public:
        \param userPassword the Latin1-encoded user ("open") password
        to use in loading the file
 
-       \return the loaded document, or NULL on error
-
-       \note The caller owns the pointer to Document, and this should
-       be deleted when no longer required.
+       \return the loaded document, or empty unique pointer on error
 
        \warning The returning document may be locked if a password is required
        to open the file, and one is not provided (as the userPassword).
     */
-    static Document *loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword = QByteArray(), const QByteArray &userPassword = QByteArray());
+    static std::unique_ptr<Document> loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword = QByteArray(), const QByteArray &userPassword = QByteArray());
 
     /**
        Get a specified Page
@@ -1234,13 +1213,11 @@ public:
        Note that this follows the PDF standard of being zero based - if you
        want the first page, then you need an index of zero.
 
-       The caller gets the ownership of the returned object.
-
-       This function can return nullptr if for some reason the page can't be properly parsed.
+       This function can return empty unique pointer if for some reason the page can't be properly parsed.
 
        \param index the page number index
     */
-    Page *page(int index) const;
+    std::unique_ptr<Page> page(int index) const;
 
     /**
        \overload
@@ -1254,7 +1231,7 @@ public:
 
        \param label the page label
     */
-    Page *page(const QString &label) const;
+    std::unique_ptr<Page> page(const QString &label) const;
 
     /**
        The number of pages in the document
@@ -1562,14 +1539,11 @@ QString subject = m_doc->info("Subject");
        The new iterator can be used for reading the font information of the
        document, reading page by page.
 
-       The caller is responsible for the returned object, ie it should freed
-       it when no more useful.
-
        \param startPage the initial page from which start reading fonts
 
        \see fonts()
     */
-    FontIterator *newFontIterator(int startPage = 0) const;
+    std::unique_ptr<FontIterator> newFontIterator(int startPage = 0) const;
 
     /**
        The font data if the font is an embedded one.
@@ -1581,6 +1555,8 @@ QString subject = m_doc->info("Subject");
 
        \note there are two types of embedded document - this call
        only accesses documents that are embedded at the document level.
+
+       \note The ownership of the EmbeddedFile objects remain with the callee.
     */
     QList<EmbeddedFile *> embeddedFiles() const;
 
@@ -1602,9 +1578,9 @@ QString subject = m_doc->info("Subject");
        \note this operation starts a search through the whole document
 
        \returns a new LinkDestination object if the named destination was
-       actually found, or NULL otherwise
+       actually found, or empty unique pointer otherwise
     */
-    LinkDestination *linkDestination(const QString &name);
+    std::unique_ptr<LinkDestination> linkDestination(const QString &name);
 
     /**
       Sets the paper color
@@ -1652,17 +1628,13 @@ QString subject = m_doc->info("Subject");
 
     /**
       Gets a new PS converter for this document.
-
-      The caller gets the ownership of the returned converter.
      */
-    PSConverter *psConverter() const;
+    std::unique_ptr<PSConverter> psConverter() const;
 
     /**
       Gets a new PDF converter for this document.
-
-      The caller gets the ownership of the returned converter.
      */
-    PDFConverter *pdfConverter() const;
+    std::unique_ptr<PDFConverter> pdfConverter() const;
 
     /**
       Gets the metadata stream contents
@@ -1724,7 +1696,7 @@ QString subject = m_doc->info("Subject");
      Prefer to use this over getting the signatures for all the pages of the document
      since there are documents with signatures that don't belong to a given page
     */
-    QVector<FormFieldSignature *> signatures() const;
+    std::vector<std::unique_ptr<FormFieldSignature>> signatures() const;
 
     /**
      Returns whether the document's XRef table has been reconstructed or not
@@ -2136,7 +2108,9 @@ public:
         ALaw ///< A-law-encoded samples
     };
 
-    /// \cond PRIVATE
+    /** \cond PRIVATE
+      The caller keeps the ownership of the popplersound argument
+    */
     SoundObject(Sound *popplersound);
     /// \endcond
 
diff --git a/qt6/tests/check_actualtext.cpp b/qt6/tests/check_actualtext.cpp
index 277db51c..1aa4ba67 100644
--- a/qt6/tests/check_actualtext.cpp
+++ b/qt6/tests/check_actualtext.cpp
@@ -14,28 +14,23 @@ private slots:
     void checkActualText2();
 
 private:
-    void checkActualText(Poppler::Document *doc);
+    void checkActualText(Poppler::Document &doc);
 };
 
-void TestActualText::checkActualText(Poppler::Document *doc)
+void TestActualText::checkActualText(Poppler::Document &doc)
 {
-    Poppler::Page *page = doc->page(0);
+    std::unique_ptr<Poppler::Page> page = doc.page(0);
     QVERIFY(page);
 
     QCOMPARE(page->text(QRectF()), QLatin1String("The slow brown fox jumps over the black dog."));
-
-    delete page;
 }
 
 void TestActualText::checkActualText1()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf");
     QVERIFY(doc);
 
-    checkActualText(doc);
-
-    delete doc;
+    checkActualText(*doc);
 }
 
 void TestActualText::checkActualText2()
@@ -43,13 +38,10 @@ void TestActualText::checkActualText2()
     QFile file(TESTDATADIR "/unittestcases/WithActualText.pdf");
     QVERIFY(file.open(QIODevice::ReadOnly));
 
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(&file);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(&file);
     QVERIFY(doc);
 
-    checkActualText(doc);
-
-    delete doc;
+    checkActualText(*doc);
 }
 
 QTEST_GUILESS_MAIN(TestActualText)
diff --git a/qt6/tests/check_annotations.cpp b/qt6/tests/check_annotations.cpp
index c8f38044..d0cd2fc6 100644
--- a/qt6/tests/check_annotations.cpp
+++ b/qt6/tests/check_annotations.cpp
@@ -90,18 +90,17 @@ void TestAnnotations::checkFontSizeAndColor()
         auto annots = page->annotations();
         QCOMPARE(annots.size(), static_cast<int>(testColors.size()));
 
-        auto &&annot = annots.constBegin();
+        auto &&annot = annots.cbegin();
         for (const auto &color : testColors) {
             QCOMPARE((*annot)->subType(), Poppler::Annotation::AText);
-            auto textAnnot = static_cast<Poppler::TextAnnotation *>(*annot);
+            auto textAnnot = static_cast<Poppler::TextAnnotation *>(annot->get());
             QCOMPARE(textAnnot->contents(), contents);
             QCOMPARE(textAnnot->textFont().pointSize(), testFont.pointSize());
             QCOMPARE(static_cast<int>(textAnnot->textColor().spec()), static_cast<int>(color.spec()));
             QCOMPARE(textAnnot->textColor(), color);
-            if (annot != annots.constEnd())
+            if (annot != annots.cend())
                 ++annot;
         }
-        qDeleteAll(annots);
     }
 }
 
@@ -139,10 +138,8 @@ void TestAnnotations::checkUTF16LEAnnot()
     auto annots = page->annotations();
     QCOMPARE(annots.size(), 2);
 
-    auto annot = annots[1];
+    const auto &annot = annots[1];
     QCOMPARE(annot->contents(), QString::fromUtf8("Únîcödé豰")); // clazy:exclude=qstring-allocations
-
-    qDeleteAll(annots);
 }
 
 void TestAnnotations::saveAndCheck(const std::unique_ptr<Poppler::Document> &doc, const std::function<void(Poppler::Annotation *a)> &checkFunction)
@@ -160,8 +157,7 @@ void TestAnnotations::saveAndCheck(const std::unique_ptr<Poppler::Document> &doc
     std::unique_ptr<Poppler::Document> savedDoc { Poppler::Document::load(tempFile.fileName()) };
     std::unique_ptr<Poppler::Page> page { doc->page(0) };
     auto annots = page->annotations();
-    checkFunction(annots.at(1));
-    qDeleteAll(annots);
+    checkFunction(annots.at(1).get());
 }
 
 void TestAnnotations::checkModificationCreationDate()
@@ -172,7 +168,7 @@ void TestAnnotations::checkModificationCreationDate()
     std::unique_ptr<Poppler::Page> page { doc->page(0) };
 
     auto annots = page->annotations();
-    auto annot = annots.at(1);
+    const auto &annot = annots.at(1);
     QCOMPARE(annot->creationDate(), QDateTime());
     QCOMPARE(annot->modificationDate(), QDateTime());
 
@@ -183,13 +179,13 @@ void TestAnnotations::checkModificationCreationDate()
         // setting the creation date updates the modification date
         QVERIFY(std::abs(a->modificationDate().secsTo(QDateTime::currentDateTime())) < 2);
     };
-    checkFunction1(annot);
+    checkFunction1(annot.get());
     saveAndCheck(doc, checkFunction1);
 
     const QDateTime dt2(QDate(2020, 8, 30), QTime(8, 14, 52));
     annot->setModificationDate(dt2);
     auto checkFunction2 = [dt2](Poppler::Annotation *a) { QCOMPARE(a->modificationDate(), dt2); };
-    checkFunction2(annot);
+    checkFunction2(annot.get());
     saveAndCheck(doc, checkFunction2);
 
     // setting the creation date to empty means "use the modification date" and also updates the modification date
@@ -199,7 +195,7 @@ void TestAnnotations::checkModificationCreationDate()
         QVERIFY(std::abs(a->creationDate().secsTo(QDateTime::currentDateTime())) < 2);
         QCOMPARE(a->creationDate(), a->modificationDate());
     };
-    checkFunction3(annot);
+    checkFunction3(annot.get());
     saveAndCheck(doc, checkFunction3);
 
     annot->setModificationDate(QDateTime());
@@ -207,10 +203,8 @@ void TestAnnotations::checkModificationCreationDate()
         QCOMPARE(a->creationDate(), QDateTime());
         QCOMPARE(a->modificationDate(), QDateTime());
     };
-    checkFunction4(annot);
+    checkFunction4(annot.get());
     saveAndCheck(doc, checkFunction4);
-
-    qDeleteAll(annots);
 }
 
 void TestAnnotations::checkNonMarkupAnnotations()
@@ -223,7 +217,6 @@ void TestAnnotations::checkNonMarkupAnnotations()
 
     auto annots = page->annotations();
     QCOMPARE(annots.size(), 17);
-    qDeleteAll(annots);
 }
 
 void TestAnnotations::checkDefaultAppearance()
diff --git a/qt6/tests/check_attachments.cpp b/qt6/tests/check_attachments.cpp
index 077ed5ef..f586a921 100644
--- a/qt6/tests/check_attachments.cpp
+++ b/qt6/tests/check_attachments.cpp
@@ -19,20 +19,15 @@ private slots:
 
 void TestAttachments::checkNoAttachments()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->hasEmbeddedFiles(), false);
-
-    delete doc;
 }
 
 void TestAttachments::checkAttach1()
 {
-
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithAttachments.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithAttachments.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasEmbeddedFiles());
@@ -65,15 +60,11 @@ void TestAttachments::checkAttach1()
     QByteArray g64Data = file2.readAll();
     QByteArray emb2data = embfile2->data();
     QCOMPARE(g64Data, emb2data);
-
-    delete doc;
 }
 
 void TestAttachments::checkAttach2()
 {
-
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/A6EmbeddedFiles.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/A6EmbeddedFiles.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasEmbeddedFiles());
@@ -102,15 +93,11 @@ void TestAttachments::checkAttach2()
     QCOMPARE(embfile3->createDate(), QDateTime(QDate(2003, 1, 31), QTime(15, 54, 29), Qt::UTC));
     QCOMPARE(embfile3->modDate(), QDateTime(QDate(2003, 1, 31), QTime(15, 52, 58), Qt::UTC));
     QCOMPARE(embfile3->mimeType(), QString());
-
-    delete doc;
 }
 
 void TestAttachments::checkAttach3()
 {
-
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/shapes+attachments.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/shapes+attachments.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasEmbeddedFiles());
@@ -125,14 +112,11 @@ void TestAttachments::checkAttach3()
     QCOMPARE(embfile->createDate(), QDateTime(QDate(2004, 3, 29), QTime(19, 37, 16), Qt::UTC));
     QCOMPARE(embfile->modDate(), QDateTime(QDate(2004, 3, 29), QTime(19, 37, 16), Qt::UTC));
     QCOMPARE(embfile->mimeType(), QString());
-    delete doc;
 }
 
 void TestAttachments::checkAttach4()
 {
-
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/imageretrieve+attachment.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/imageretrieve+attachment.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasEmbeddedFiles());
@@ -147,7 +131,6 @@ void TestAttachments::checkAttach4()
     QCOMPARE(embfile->createDate(), QDateTime(QDate(2005, 8, 30), QTime(20, 49, 35), Qt::UTC));
     QCOMPARE(embfile->modDate(), QDateTime(QDate(2005, 8, 30), QTime(20, 49, 52), Qt::UTC));
     QCOMPARE(embfile->mimeType(), QLatin1String("application/vnd.ms-excel"));
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestAttachments)
diff --git a/qt6/tests/check_fonts.cpp b/qt6/tests/check_fonts.cpp
index f4f747ac..12864454 100644
--- a/qt6/tests/check_fonts.cpp
+++ b/qt6/tests/check_fonts.cpp
@@ -53,20 +53,16 @@ static bool operator==(const FontInfo &f1, const FontInfo &f2)
 
 void TestFontsData::checkNoFonts()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/image.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/image.pdf");
     QVERIFY(doc);
 
     QList<Poppler::FontInfo> listOfFonts = doc->fonts();
     QCOMPARE(listOfFonts.size(), 0);
-
-    delete doc;
 }
 
 void TestFontsData::checkType1()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/text.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/text.pdf");
     QVERIFY(doc);
 
     QList<Poppler::FontInfo> listOfFonts = doc->fonts();
@@ -77,14 +73,11 @@ void TestFontsData::checkType1()
 
     QCOMPARE(listOfFonts.at(0).isEmbedded(), false);
     QCOMPARE(listOfFonts.at(0).isSubset(), false);
-
-    delete doc;
 }
 
 void TestFontsData::checkType3()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
     QVERIFY(doc);
 
     QList<Poppler::FontInfo> listOfFonts = doc->fonts();
@@ -102,14 +95,11 @@ void TestFontsData::checkType3()
 
     QCOMPARE(listOfFonts.at(1).isEmbedded(), true);
     QCOMPARE(listOfFonts.at(1).isSubset(), false);
-
-    delete doc;
 }
 
 void TestFontsData::checkTrueType()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
 
     QList<Poppler::FontInfo> listOfFonts = doc->fonts();
@@ -127,47 +117,44 @@ void TestFontsData::checkTrueType()
 
     QCOMPARE(listOfFonts.at(1).isEmbedded(), false);
     QCOMPARE(listOfFonts.at(1).isSubset(), false);
-
-    delete doc;
 }
 
 void TestFontsData::checkFontIterator()
 {
     // loading a 1-page document
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
     QVERIFY(doc);
     // loading a 6-pages document
-    Poppler::Document *doc6 = Poppler::Document::load(TESTDATADIR "/tests/cropbox.pdf");
+    std::unique_ptr<Poppler::Document> doc6 = Poppler::Document::load(TESTDATADIR "/tests/cropbox.pdf");
     QVERIFY(doc6);
 
     std::unique_ptr<Poppler::FontIterator> it;
 
     // some tests with the 1-page document:
     // - check a default iterator
-    it.reset(doc->newFontIterator());
+    it = doc->newFontIterator();
     QVERIFY(it->hasNext());
     // - check an iterator for negative pages to behave as 0
-    it.reset(doc->newFontIterator(-1));
+    it = doc->newFontIterator(-1);
     QVERIFY(it->hasNext());
     // - check an iterator for pages out of the page limit
-    it.reset(doc->newFontIterator(1));
+    it = doc->newFontIterator(1);
     QVERIFY(!it->hasNext());
     // - check that it reaches the end after 1 iteration
-    it.reset(doc->newFontIterator());
+    it = doc->newFontIterator();
     QVERIFY(it->hasNext());
     it->next();
     QVERIFY(!it->hasNext());
 
     // some tests with the 6-page document:
     // - check a default iterator
-    it.reset(doc6->newFontIterator());
+    it = doc6->newFontIterator();
     QVERIFY(it->hasNext());
     // - check an iterator for pages out of the page limit
-    it.reset(doc6->newFontIterator(6));
+    it = doc6->newFontIterator(6);
     QVERIFY(!it->hasNext());
     // - check that it reaches the end after 6 iterations
-    it.reset(doc6->newFontIterator());
+    it = doc6->newFontIterator();
     QVERIFY(it->hasNext());
     it->next();
     QVERIFY(it->hasNext());
@@ -181,15 +168,11 @@ void TestFontsData::checkFontIterator()
     QVERIFY(it->hasNext());
     it->next();
     QVERIFY(!it->hasNext());
-
-    delete doc;
-    delete doc6;
 }
 
 void TestFontsData::checkSecondDocumentQuery()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
     QVERIFY(doc);
 
     QList<Poppler::FontInfo> listOfFonts = doc->fonts();
@@ -197,38 +180,30 @@ void TestFontsData::checkSecondDocumentQuery()
     // check we get the very same result when calling fonts() again (#19405)
     QList<Poppler::FontInfo> listOfFonts2 = doc->fonts();
     QCOMPARE(listOfFonts, listOfFonts2);
-
-    delete doc;
 }
 
 void TestFontsData::checkMultipleIterations()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/type3.pdf");
     QVERIFY(doc);
 
-    QList<Poppler::FontInfo> listOfFonts = loadFontsViaIterator(doc);
+    QList<Poppler::FontInfo> listOfFonts = loadFontsViaIterator(doc.get());
     QCOMPARE(listOfFonts.size(), 2);
-    QList<Poppler::FontInfo> listOfFonts2 = loadFontsViaIterator(doc);
+    QList<Poppler::FontInfo> listOfFonts2 = loadFontsViaIterator(doc.get());
     QCOMPARE(listOfFonts, listOfFonts2);
-
-    delete doc;
 }
 
 void TestFontsData::checkIteratorFonts()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/tests/fonts.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/tests/fonts.pdf");
     QVERIFY(doc);
 
     QList<Poppler::FontInfo> listOfFonts = doc->fonts();
     QCOMPARE(listOfFonts.size(), 3);
 
     // check we get the very same result when gatering fonts using the iterator
-    QList<Poppler::FontInfo> listOfFonts2 = loadFontsViaIterator(doc);
+    QList<Poppler::FontInfo> listOfFonts2 = loadFontsViaIterator(doc.get());
     QCOMPARE(listOfFonts, listOfFonts2);
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestFontsData)
diff --git a/qt6/tests/check_forms.cpp b/qt6/tests/check_forms.cpp
index f5df258e..841fcafb 100644
--- a/qt6/tests/check_forms.cpp
+++ b/qt6/tests/check_forms.cpp
@@ -23,16 +23,16 @@ private slots:
 void TestForms::testCheckbox()
 {
     // Test for checkbox issue #655
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/latex-hyperref-checkbox-issue-655.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/latex-hyperref-checkbox-issue-655.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page(document->page(0));
     QVERIFY(page);
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
     QCOMPARE(forms.size(), 1);
 
-    Poppler::FormField *form = forms.at(0);
+    Poppler::FormField *form = forms.at(0).get();
     QCOMPARE(form->type(), Poppler::FormField::FormButton);
 
     Poppler::FormFieldButton *chkFormFieldButton = static_cast<Poppler::FormFieldButton *>(form);
@@ -51,20 +51,20 @@ void TestForms::testCheckbox()
 void TestForms::testStandAloneWidgets()
 {
     // Check for 'de facto' tooltips. Issue #34
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/tooltip.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/tooltip.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
 
     QCOMPARE(forms.size(), 3);
 
-    Q_FOREACH (Poppler::FormField *field, forms) {
+    for (const std::unique_ptr<Poppler::FormField> &field : forms) {
         QCOMPARE(field->type(), Poppler::FormField::FormButton);
 
-        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field);
+        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field.get());
         QCOMPARE(fieldButton->buttonType(), Poppler::FormFieldButton::Push);
 
         FormField *ff = Poppler::FormFieldData::getFormWidget(fieldButton)->getField();
@@ -80,23 +80,23 @@ void TestForms::testStandAloneWidgets()
 void TestForms::testCheckboxIssue159()
 {
     // Test for checkbox issue #159
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     Poppler::FormFieldButton *beerFieldButton = nullptr;
     Poppler::FormFieldButton *wineFieldButton = nullptr;
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
 
     // Let's find and assign the "Wine" and "Beer" radio buttons
-    Q_FOREACH (Poppler::FormField *field, forms) {
+    for (const std::unique_ptr<Poppler::FormField> &field : forms) {
         if (field->type() != Poppler::FormField::FormButton)
             continue;
 
-        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field);
+        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field.get());
         if (fieldButton->buttonType() != Poppler::FormFieldButton::Radio)
             continue;
 
@@ -125,23 +125,23 @@ void TestForms::testCheckboxIssue159()
 
 void TestForms::testSetIcon()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/form_set_icon.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/form_set_icon.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
 
     Poppler::FormFieldButton *anmButton = nullptr;
 
     // First we are finding the field which will have its icon changed
-    Q_FOREACH (Poppler::FormField *field, forms) {
+    for (const std::unique_ptr<Poppler::FormField> &field : forms) {
 
         if (field->type() != Poppler::FormField::FormButton)
             continue;
 
-        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field);
+        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field.get());
         if (field->name() == QStringLiteral("anm0"))
             anmButton = fieldButton;
     }
@@ -150,12 +150,12 @@ void TestForms::testSetIcon()
 
     // Then we set the Icon on this field, for every other field
     // And verify if it has a valid icon
-    Q_FOREACH (Poppler::FormField *field, forms) {
+    for (const std::unique_ptr<Poppler::FormField> &field : forms) {
 
         if (field->type() != Poppler::FormField::FormButton)
             continue;
 
-        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field);
+        Poppler::FormFieldButton *fieldButton = static_cast<Poppler::FormFieldButton *>(field.get());
         if (field->name() == QStringLiteral("anm0"))
             continue;
 
@@ -181,15 +181,15 @@ void TestForms::testSetIcon()
 
 void TestForms::testSetPrintable()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/form_set_icon.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/form_set_icon.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
 
-    Q_FOREACH (Poppler::FormField *field, forms) {
+    for (std::unique_ptr<Poppler::FormField> &field : forms) {
         field->setPrintable(true);
         QCOMPARE(field->isPrintable(), true);
 
@@ -200,24 +200,24 @@ void TestForms::testSetPrintable()
 
 void TestForms::testSetAppearanceText()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
 
     int nTextForms = 0;
 
-    Q_FOREACH (Poppler::FormField *field, forms) {
+    for (std::unique_ptr<Poppler::FormField> &field : forms) {
 
         if (field->type() != Poppler::FormField::FormText)
             continue;
 
         nTextForms++;
 
-        Poppler::FormFieldText *fft = static_cast<Poppler::FormFieldText *>(field);
+        Poppler::FormFieldText *fft = static_cast<Poppler::FormFieldText *>(field.get());
 
         const QString textToSet = "HOLA" + fft->name();
         fft->setAppearanceText(textToSet);
@@ -239,15 +239,15 @@ void TestForms::testSetAppearanceText()
 
 void TestForms::testUnicodeFieldAttributes()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/fieldWithUtf16Names.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/fieldWithUtf16Names.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
-    QList<Poppler::FormField *> forms = page->formFields();
+    std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
 
-    Poppler::FormField *field = forms.first();
+    Poppler::FormField *field = forms.front().get();
 
     QCOMPARE(field->name(), QStringLiteral("Tex"));
     QCOMPARE(field->uiName(), QStringLiteral("Texto de ayuda"));
diff --git a/qt6/tests/check_links.cpp b/qt6/tests/check_links.cpp
index 27ab7119..52112400 100644
--- a/qt6/tests/check_links.cpp
+++ b/qt6/tests/check_links.cpp
@@ -28,92 +28,74 @@ static bool isDestinationValid_name(const Poppler::LinkDestination *dest)
 
 void TestLinks::checkDocumentWithNoDests()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithAttachments.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithAttachments.pdf");
     QVERIFY(doc);
 
-    std::unique_ptr<Poppler::LinkDestination> dest;
-    dest.reset(doc->linkDestination(QStringLiteral("no.dests.in.this.document")));
-    QVERIFY(!isDestinationValid_pageNumber(dest.get(), doc));
+    std::unique_ptr<Poppler::LinkDestination> dest = doc->linkDestination(QStringLiteral("no.dests.in.this.document"));
+    QVERIFY(!isDestinationValid_pageNumber(dest.get(), doc.get()));
     QVERIFY(isDestinationValid_name(dest.get()));
-
-    delete doc;
 }
 
 void TestLinks::checkDests_xr01()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf");
     QVERIFY(doc);
 
-    Poppler::Page *page = doc->page(0);
+    std::unique_ptr<Poppler::Page> page = doc->page(0);
     QVERIFY(page);
 
-    QList<Poppler::Link *> links = page->links();
-    QCOMPARE(links.count(), 2);
+    std::vector<std::unique_ptr<Poppler::Link>> links = page->links();
+    QCOMPARE(links.size(), 2);
 
     {
         QCOMPARE(links.at(0)->linkType(), Poppler::Link::Goto);
-        Poppler::LinkGoto *link = static_cast<Poppler::LinkGoto *>(links.at(0));
+        Poppler::LinkGoto *link = static_cast<Poppler::LinkGoto *>(links.at(0).get());
         const Poppler::LinkDestination dest = link->destination();
-        QVERIFY(!isDestinationValid_pageNumber(&dest, doc));
+        QVERIFY(!isDestinationValid_pageNumber(&dest, doc.get()));
         QVERIFY(isDestinationValid_name(&dest));
         QCOMPARE(dest.destinationName(), QLatin1String("section.1"));
     }
 
     {
         QCOMPARE(links.at(1)->linkType(), Poppler::Link::Goto);
-        Poppler::LinkGoto *link = static_cast<Poppler::LinkGoto *>(links.at(1));
+        Poppler::LinkGoto *link = static_cast<Poppler::LinkGoto *>(links.at(1).get());
         const Poppler::LinkDestination dest = link->destination();
-        QVERIFY(!isDestinationValid_pageNumber(&dest, doc));
+        QVERIFY(!isDestinationValid_pageNumber(&dest, doc.get()));
         QVERIFY(isDestinationValid_name(&dest));
         QCOMPARE(dest.destinationName(), QLatin1String("section.2"));
     }
-
-    qDeleteAll(links);
-    delete page;
-    delete doc;
 }
 
 void TestLinks::checkDests_xr02()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/xr02.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/xr02.pdf");
     QVERIFY(doc);
 
-    std::unique_ptr<Poppler::LinkDestination> dest;
-    dest.reset(doc->linkDestination(QStringLiteral("section.1")));
-    QVERIFY(isDestinationValid_pageNumber(dest.get(), doc));
+    std::unique_ptr<Poppler::LinkDestination> dest = doc->linkDestination(QStringLiteral("section.1"));
+    QVERIFY(isDestinationValid_pageNumber(dest.get(), doc.get()));
     QVERIFY(!isDestinationValid_name(dest.get()));
-    dest.reset(doc->linkDestination(QStringLiteral("section.2")));
-    QVERIFY(isDestinationValid_pageNumber(dest.get(), doc));
+    dest = doc->linkDestination(QStringLiteral("section.2"));
+    QVERIFY(isDestinationValid_pageNumber(dest.get(), doc.get()));
     QVERIFY(!isDestinationValid_name(dest.get()));
-    dest.reset(doc->linkDestination(QStringLiteral("section.3")));
-    QVERIFY(!isDestinationValid_pageNumber(dest.get(), doc));
+    dest = doc->linkDestination(QStringLiteral("section.3"));
+    QVERIFY(!isDestinationValid_pageNumber(dest.get(), doc.get()));
     QVERIFY(isDestinationValid_name(dest.get()));
-
-    delete doc;
 }
 
 void TestLinks::checkDocumentURILink()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf");
     QVERIFY(doc);
 
-    Poppler::Page *page = doc->page(0);
+    std::unique_ptr<Poppler::Page> page = doc->page(0);
     QVERIFY(page);
 
-    QList<Poppler::Link *> links = page->links();
-    QCOMPARE(links.count(), 1);
+    std::vector<std::unique_ptr<Poppler::Link>> links = page->links();
+    QCOMPARE(links.size(), 1);
 
     QCOMPARE(links.at(0)->linkType(), Poppler::Link::Browse);
-    Poppler::LinkBrowse *link = static_cast<Poppler::LinkBrowse *>(links.at(0));
+    Poppler::LinkBrowse *link = static_cast<Poppler::LinkBrowse *>(links.at(0).get());
     QCOMPARE(link->url(), QLatin1String("http://www.tcpdf.org"));
-
-    qDeleteAll(links);
-    delete page;
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestLinks)
diff --git a/qt6/tests/check_metadata.cpp b/qt6/tests/check_metadata.cpp
index a97f3c11..2a456bed 100644
--- a/qt6/tests/check_metadata.cpp
+++ b/qt6/tests/check_metadata.cpp
@@ -47,15 +47,12 @@ void TestMetaData::checkStrings_data()
 
 void TestMetaData::checkStrings()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
     QVERIFY(doc);
 
     QFETCH(QString, key);
     QFETCH(QString, value);
     QCOMPARE(doc->info(key), value);
-
-    delete doc;
 }
 
 void TestMetaData::checkStrings2_data()
@@ -81,21 +78,17 @@ void TestMetaData::checkStrings2_data()
 
 void TestMetaData::checkStrings2()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
 
     QFETCH(QString, key);
     QFETCH(QString, value);
     QCOMPARE(doc->info(key), value);
-
-    delete doc;
 }
 
 void TestMetaData::checkStringKeys()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
 
     QStringList keyList;
@@ -105,139 +98,98 @@ void TestMetaData::checkStringKeys()
     QStringList keysInDoc = doc->infoKeys();
     keysInDoc.sort();
     QCOMPARE(keysInDoc, keyList);
-
-    delete doc;
 }
 
 void TestMetaData::checkLinearised()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->isLinearized());
 
-    delete doc;
-
     doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
     QCOMPARE(doc->isLinearized(), false);
-
-    delete doc;
 }
 
 void TestMetaData::checkPortraitOrientation()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
-    Poppler::Page *page = doc->page(0);
+    std::unique_ptr<Poppler::Page> page = doc->page(0);
     QCOMPARE(page->orientation(), Poppler::Page::Portrait);
-
-    delete page;
-    delete doc;
 }
 
 void TestMetaData::checkNumPages()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
     QVERIFY(doc);
     QCOMPARE(doc->numPages(), 2);
 
-    delete doc;
-
     doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
     QCOMPARE(doc->numPages(), 1);
-
-    delete doc;
 }
 
 void TestMetaData::checkDate()
 {
-    Poppler::Document *doc;
-
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
     QCOMPARE(doc->date(QStringLiteral("ModDate")), QDateTime(QDate(2005, 12, 5), QTime(9, 44, 46), Qt::UTC));
     QCOMPARE(doc->date(QStringLiteral("CreationDate")), QDateTime(QDate(2005, 8, 13), QTime(1, 12, 11), Qt::UTC));
-
-    delete doc;
 }
 
 void TestMetaData::checkPageSize()
 {
-    Poppler::Document *doc;
-
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
     QVERIFY(doc);
-    Poppler::Page *page = doc->page(0);
+    std::unique_ptr<Poppler::Page> page = doc->page(0);
     QCOMPARE(page->pageSize(), QSize(595, 842));
     QCOMPARE(page->pageSizeF(), QSizeF(595.22, 842));
-
-    delete page;
-    delete doc;
 }
 
 void TestMetaData::checkLandscapeOrientation()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
-    Poppler::Page *page = doc->page(1);
+    std::unique_ptr<Poppler::Page> page = doc->page(1);
     QCOMPARE(page->orientation(), Poppler::Page::Landscape);
-
-    delete page;
-    delete doc;
 }
 
 void TestMetaData::checkUpsideDownOrientation()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
-    Poppler::Page *page = doc->page(2);
+    std::unique_ptr<Poppler::Page> page = doc->page(2);
     QCOMPARE(page->orientation(), Poppler::Page::UpsideDown);
-
-    delete page;
-    delete doc;
 }
 
 void TestMetaData::checkSeascapeOrientation()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
-    Poppler::Page *page = doc->page(3);
+    std::unique_ptr<Poppler::Page> page = doc->page(3);
     QCOMPARE(page->orientation(), Poppler::Page::Seascape);
-
-    delete page;
-    delete doc;
 }
 
 void TestMetaData::checkVersion()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
     QVERIFY(doc);
 
     int major = 0, minor = 0;
     doc->getPdfVersion(&major, &minor);
     QCOMPARE(major, 1);
     QCOMPARE(minor, 6);
-
-    delete doc;
 }
 
 void TestMetaData::checkPdfId()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/A6EmbeddedFiles.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/A6EmbeddedFiles.pdf");
     QVERIFY(doc);
 
     const QByteArray referencePermanentId("00C9D5B6D8FB11D7A902003065D630AA");
@@ -267,19 +219,14 @@ void TestMetaData::checkPdfId()
         QCOMPARE(permanentId.toUpper(), referencePermanentId);
         QCOMPARE(updateId.toUpper(), referenceUpdateId);
     }
-
-    delete doc;
 }
 
 void TestMetaData::checkNoPdfId()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf");
     QVERIFY(doc);
 
     QVERIFY(!doc->getPdfId(nullptr, nullptr));
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestMetaData)
diff --git a/qt6/tests/check_optcontent.cpp b/qt6/tests/check_optcontent.cpp
index 004449cd..e417c034 100644
--- a/qt6/tests/check_optcontent.cpp
+++ b/qt6/tests/check_optcontent.cpp
@@ -22,8 +22,7 @@ private slots:
 
 void TestOptionalContent::checkVisPolicy()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/vis_policy_test.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/vis_policy_test.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasOptionalContent());
@@ -36,14 +35,11 @@ void TestOptionalContent::checkVisPolicy()
     index = optContent->index(1, 0, QModelIndex());
     QCOMPARE(optContent->data(index, Qt::DisplayRole).toString(), QLatin1String("B"));
     QCOMPARE(static_cast<Qt::CheckState>(optContent->data(index, Qt::CheckStateRole).toInt()), Qt::Checked);
-
-    delete doc;
 }
 
 void TestOptionalContent::checkNestedLayers()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/NestedLayers.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/NestedLayers.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasOptionalContent());
@@ -71,19 +67,14 @@ void TestOptionalContent::checkNestedLayers()
     index = optContent->index(3, 0, QModelIndex());
     QCOMPARE(optContent->data(index, Qt::DisplayRole).toString(), QLatin1String("Watermark"));
     QCOMPARE(static_cast<Qt::CheckState>(optContent->data(index, Qt::CheckStateRole).toInt()), Qt::Unchecked);
-
-    delete doc;
 }
 
 void TestOptionalContent::checkNoOptionalContent()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->hasOptionalContent(), false);
-
-    delete doc;
 }
 
 void TestOptionalContent::checkIsVisible()
@@ -365,8 +356,7 @@ void TestOptionalContent::checkVisibilitySetting()
 
 void TestOptionalContent::checkRadioButtons()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/ClarityOCGs.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/ClarityOCGs.pdf");
     QVERIFY(doc);
 
     QVERIFY(doc->hasOptionalContent());
@@ -444,8 +434,6 @@ void TestOptionalContent::checkRadioButtons()
     QCOMPARE(optContent->data(subindex, Qt::DisplayRole).toString(), QLatin1String("French"));
     QCOMPARE(static_cast<Qt::CheckState>(optContent->data(subindex, Qt::CheckStateRole).toInt()), Qt::Unchecked);
     QCOMPARE(static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off);
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestOptionalContent)
diff --git a/qt6/tests/check_pagelayout.cpp b/qt6/tests/check_pagelayout.cpp
index 01a2ec8b..a61a8d5f 100644
--- a/qt6/tests/check_pagelayout.cpp
+++ b/qt6/tests/check_pagelayout.cpp
@@ -15,35 +15,26 @@ private slots:
 
 void TestPageLayout::checkNone()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseNone.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseNone.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageLayout(), Poppler::Document::NoLayout);
-
-    delete doc;
 }
 
 void TestPageLayout::checkSingle()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/FullScreen.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/FullScreen.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageLayout(), Poppler::Document::SinglePage);
-
-    delete doc;
 }
 
 void TestPageLayout::checkFacing()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageLayout(), Poppler::Document::TwoPageRight);
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestPageLayout)
diff --git a/qt6/tests/check_pagemode.cpp b/qt6/tests/check_pagemode.cpp
index 4e830cc4..80707413 100644
--- a/qt6/tests/check_pagemode.cpp
+++ b/qt6/tests/check_pagemode.cpp
@@ -17,57 +17,42 @@ private slots:
 
 void TestPageMode::checkNone()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseNone.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseNone.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageMode(), Poppler::Document::UseNone);
-
-    delete doc;
 }
 
 void TestPageMode::checkFullScreen()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/FullScreen.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/FullScreen.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageMode(), Poppler::Document::FullScreen);
-
-    delete doc;
 }
 
 void TestPageMode::checkAttachments()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseAttachments.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseAttachments.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageMode(), Poppler::Document::UseAttach);
-
-    delete doc;
 }
 
 void TestPageMode::checkThumbs()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseThumbs.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseThumbs.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageMode(), Poppler::Document::UseThumbs);
-
-    delete doc;
 }
 
 void TestPageMode::checkOC()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseOC.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/UseOC.pdf");
     QVERIFY(doc);
 
     QCOMPARE(doc->pageMode(), Poppler::Document::UseOC);
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestPageMode)
diff --git a/qt6/tests/check_password.cpp b/qt6/tests/check_password.cpp
index 20b2bbd7..e41cfced 100644
--- a/qt6/tests/check_password.cpp
+++ b/qt6/tests/check_password.cpp
@@ -21,94 +21,70 @@ private slots:
 // BUG:4557
 void TestPassword::password1()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf"), "", QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf"), "", QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
     QVERIFY(doc);
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 void TestPassword::password1a()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf")); // clazy:exclude=qstring-allocations
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf")); // clazy:exclude=qstring-allocations
     QVERIFY(doc);
     QVERIFY(doc->isLocked());
     QVERIFY(!doc->unlock("", QString::fromUtf8("garçon").toLatin1())); // clazy:exclude=qstring-allocations
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 void TestPassword::password2()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1(), ""); // clazy:exclude=qstring-allocations
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1(), ""); // clazy:exclude=qstring-allocations
     QVERIFY(doc);
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 void TestPassword::password2a()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
     QVERIFY(doc);
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 void TestPassword::password2b()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"));
     QVERIFY(doc);
     QVERIFY(!doc->isLocked());
     QVERIFY(!doc->unlock(QString::fromUtf8("garçon").toLatin1(), "")); // clazy:exclude=qstring-allocations
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 void TestPassword::password3()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncrypted.pdf"));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncrypted.pdf"));
     QVERIFY(doc);
     QVERIFY(doc->isLocked());
     QVERIFY(!doc->unlock("", "password"));
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 // issue 690
 void TestPassword::password4()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
     QVERIFY(doc);
     QVERIFY(doc->isLocked());
     QVERIFY(!doc->unlock("owner-secret", ""));
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 // issue 690
 void TestPassword::password4b()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
     QVERIFY(doc);
     QVERIFY(doc->isLocked());
     QVERIFY(!doc->unlock("", "user-secret"));
     QVERIFY(!doc->isLocked());
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestPassword)
diff --git a/qt6/tests/check_permissions.cpp b/qt6/tests/check_permissions.cpp
index 87a3355a..c9f94188 100644
--- a/qt6/tests/check_permissions.cpp
+++ b/qt6/tests/check_permissions.cpp
@@ -13,8 +13,7 @@ private slots:
 
 void TestPermissions::permissions1()
 {
-    Poppler::Document *doc;
-    doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/orientation.pdf");
     QVERIFY(doc);
 
     // we are allowed to print
@@ -37,8 +36,6 @@ void TestPermissions::permissions1()
 
     // we are allowed to assemble this document
     QVERIFY(doc->okToAssemble());
-
-    delete doc;
 }
 
 QTEST_GUILESS_MAIN(TestPermissions)
diff --git a/qt6/tests/check_search.cpp b/qt6/tests/check_search.cpp
index d8534975..468e799f 100644
--- a/qt6/tests/check_search.cpp
+++ b/qt6/tests/check_search.cpp
@@ -19,10 +19,10 @@ private slots:
 
 void TestSearch::bug7063()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
@@ -58,10 +58,10 @@ void TestSearch::bug7063()
 
 void TestSearch::testNextAndPrevious()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
@@ -147,10 +147,10 @@ void TestSearch::testNextAndPrevious()
 
 void TestSearch::testWholeWordsOnly()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
@@ -177,10 +177,10 @@ void TestSearch::testWholeWordsOnly()
 
 void TestSearch::testIgnoreDiacritics()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/Issue637.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/Issue637.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
@@ -236,10 +236,10 @@ void TestSearch::testIgnoreDiacritics()
 void TestSearch::testRussianSearch()
 {
     // Test for issue #743
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/russian.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/russian.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
@@ -265,10 +265,10 @@ void TestSearch::testRussianSearch()
 
 void TestSearch::testDeseretSearch()
 {
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/deseret.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/deseret.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(0));
+    std::unique_ptr<Poppler::Page> page = document->page(0);
     QVERIFY(page);
 
     double l, t, r, b; // left, top, right, bottom
@@ -285,10 +285,10 @@ void TestSearch::testAcrossLinesSearch()
     // Test for searching across lines with new flag Poppler::Page::AcrossLines
     // and its automatic features like ignoring hyphen at end of line or allowing
     // whitespace in the search term to match on newline character.
-    QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/searchAcrossLines.pdf"));
+    std::unique_ptr<Poppler::Document> document = Poppler::Document::load(TESTDATADIR "/unittestcases/searchAcrossLines.pdf");
     QVERIFY(document);
 
-    QScopedPointer<Poppler::Page> page(document->page(1));
+    std::unique_ptr<Poppler::Page> page = document->page(1);
     QVERIFY(page);
 
     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
@@ -334,7 +334,7 @@ void TestSearch::testAcrossLinesSearch()
     // then we don't automatically ignore it, but treat it as a normal char.
     // In the searched page, "CC BY-NC-SA 4.0" is split across two lines on the second hyphen
     const QString str5 = QString::fromUtf8("CC BY-NC-SA 4.0"); // clazy:exclude=qstring-allocations
-    QScopedPointer<Poppler::Page> page0(document->page(0));
+    std::unique_ptr<Poppler::Page> page0 = document->page(0);
     QVERIFY(page0);
     QCOMPARE(page0->search(str5, l, t, r, b, direction, mode0), true);
     QCOMPARE(page0->search(str5, l, t, r, b, direction, mode1), true);
diff --git a/qt6/tests/check_stroke_opacity.cpp b/qt6/tests/check_stroke_opacity.cpp
index 4ea3e1a9..2b10d1bc 100644
--- a/qt6/tests/check_stroke_opacity.cpp
+++ b/qt6/tests/check_stroke_opacity.cpp
@@ -29,7 +29,7 @@ void TestStrokeOpacity::checkStrokeOpacity()
 {
     QFETCH(int, backendType);
 
-    auto doc = std::unique_ptr<Poppler::Document>(Poppler::Document::load(TESTDATADIR "/unittestcases/stroke-alpha-pattern.pdf"));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/stroke-alpha-pattern.pdf");
     QVERIFY(doc != nullptr);
 
     doc->setRenderBackend((Poppler::Document::RenderBackend)backendType);
diff --git a/qt6/tests/poppler-attachments.cpp b/qt6/tests/poppler-attachments.cpp
index 367cb973..b45b249d 100644
--- a/qt6/tests/poppler-attachments.cpp
+++ b/qt6/tests/poppler-attachments.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(argv[1]);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[1]);
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -32,5 +32,4 @@ int main(int argc, char **argv)
     } else {
         std::cout << "There are no embedded document at the top level" << std::endl;
     }
-    delete doc;
 }
diff --git a/qt6/tests/poppler-fonts.cpp b/qt6/tests/poppler-fonts.cpp
index 140de8d1..92f60b5d 100644
--- a/qt6/tests/poppler-fonts.cpp
+++ b/qt6/tests/poppler-fonts.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(argv[1]);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[1]);
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -83,5 +83,4 @@ int main(int argc, char **argv)
         std::cout << qPrintable(font.file());
         std::cout << std::endl;
     }
-    delete doc;
 }
diff --git a/qt6/tests/poppler-forms.cpp b/qt6/tests/poppler-forms.cpp
index 57e75d87..6fc55394 100644
--- a/qt6/tests/poppler-forms.cpp
+++ b/qt6/tests/poppler-forms.cpp
@@ -195,7 +195,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(argv[1]);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[1]);
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -203,11 +203,11 @@ int main(int argc, char **argv)
 
     std::cout << "Forms for file " << argv[1] << std::endl;
     for (int i = 0; i < doc->numPages(); ++i) {
-        Poppler::Page *page = doc->page(i);
+        std::unique_ptr<Poppler::Page> page = doc->page(i);
         if (page) {
-            QList<Poppler::FormField *> forms = page->formFields();
+            std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
             std::cout << "\tPage " << i + 1 << std::endl;
-            foreach (const Poppler::FormField *form, forms) {
+            for (const std::unique_ptr<Poppler::FormField> &form : forms) {
                 std::cout << "\t\tForm" << std::endl;
                 std::cout << "\t\t\tType: " << form->type() << std::endl;
                 std::cout << "\t\t\tRect: " << form->rect() << std::endl;
@@ -219,7 +219,7 @@ int main(int argc, char **argv)
                 std::cout << "\t\t\tVisible: " << form->isVisible() << std::endl;
                 switch (form->type()) {
                 case Poppler::FormField::FormButton: {
-                    const Poppler::FormFieldButton *buttonForm = static_cast<const Poppler::FormFieldButton *>(form);
+                    const Poppler::FormFieldButton *buttonForm = static_cast<const Poppler::FormFieldButton *>(form.get());
                     std::cout << "\t\t\tButtonType: " << buttonForm->buttonType() << std::endl;
                     std::cout << "\t\t\tCaption: " << buttonForm->caption() << std::endl;
                     std::cout << "\t\t\tState: " << buttonForm->state() << std::endl;
@@ -227,7 +227,7 @@ int main(int argc, char **argv)
                 } break;
 
                 case Poppler::FormField::FormText: {
-                    const Poppler::FormFieldText *textForm = static_cast<const Poppler::FormFieldText *>(form);
+                    const Poppler::FormFieldText *textForm = static_cast<const Poppler::FormFieldText *>(form.get());
                     std::cout << "\t\t\tTextType: " << textForm->textType() << std::endl;
                     std::cout << "\t\t\tText: " << textForm->text() << std::endl;
                     std::cout << "\t\t\tIsPassword: " << textForm->isPassword() << std::endl;
@@ -238,7 +238,7 @@ int main(int argc, char **argv)
                 } break;
 
                 case Poppler::FormField::FormChoice: {
-                    const Poppler::FormFieldChoice *choiceForm = static_cast<const Poppler::FormFieldChoice *>(form);
+                    const Poppler::FormFieldChoice *choiceForm = static_cast<const Poppler::FormFieldChoice *>(form.get());
                     std::cout << "\t\t\tChoiceType: " << choiceForm->choiceType() << std::endl;
                     std::cout << "\t\t\tChoices: " << choiceForm->choices() << std::endl;
                     std::cout << "\t\t\tIsEditable: " << choiceForm->isEditable() << std::endl;
@@ -250,7 +250,7 @@ int main(int argc, char **argv)
                 } break;
 
                 case Poppler::FormField::FormSignature: {
-                    const Poppler::FormFieldSignature *signatureForm = static_cast<const Poppler::FormFieldSignature *>(form);
+                    const Poppler::FormFieldSignature *signatureForm = static_cast<const Poppler::FormFieldSignature *>(form.get());
                     const Poppler::SignatureValidationInfo svi = signatureForm->validate(Poppler::FormFieldSignature::ValidateVerifyCertificate);
                     std::cout << "\t\t\tSignatureStatus: " << svi.signatureStatus() << std::endl;
                     std::cout << "\t\t\tCertificateStatus: " << svi.certificateStatus() << std::endl;
@@ -264,9 +264,6 @@ int main(int argc, char **argv)
                 } break;
                 }
             }
-            qDeleteAll(forms);
-            delete page;
         }
     }
-    delete doc;
 }
diff --git a/qt6/tests/poppler-page-labels.cpp b/qt6/tests/poppler-page-labels.cpp
index bcb8a850..79f22fc1 100644
--- a/qt6/tests/poppler-page-labels.cpp
+++ b/qt6/tests/poppler-page-labels.cpp
@@ -15,7 +15,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(argv[1]);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[1]);
     if (!doc || doc->isLocked()) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -41,5 +41,4 @@ int main(int argc, char **argv)
         if (indexFromPageLabel != i)
             std::cout << "WARNING: Page label didn't link back to the same page index " << indexFromPageLabel << " " << i << std::endl;
     }
-    delete doc;
 }
diff --git a/qt6/tests/poppler-texts.cpp b/qt6/tests/poppler-texts.cpp
index 82c6dc58..fa77141d 100644
--- a/qt6/tests/poppler-texts.cpp
+++ b/qt6/tests/poppler-texts.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(argv[1]);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[1]);
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -25,13 +25,11 @@ int main(int argc, char **argv)
         std::cout << "*** Page " << i << std::endl;
         std::cout << std::flush;
 
-        Poppler::Page *page = doc->page(i);
+        std::unique_ptr<Poppler::Page> page = doc->page(i);
         const QByteArray utf8str = page->text(QRectF(), Poppler::Page::RawOrderLayout).toUtf8();
         std::cout << std::flush;
         for (j = 0; j < utf8str.size(); j++)
             std::cout << utf8str[j];
         std::cout << std::endl;
-        delete page;
     }
-    delete doc;
 }
diff --git a/qt6/tests/stress-poppler-dir.cpp b/qt6/tests/stress-poppler-dir.cpp
index 6f979758..9a30fc93 100644
--- a/qt6/tests/stress-poppler-dir.cpp
+++ b/qt6/tests/stress-poppler-dir.cpp
@@ -19,13 +19,12 @@ int main(int argc, char **argv)
     foreach (const QString &fileName, directory.entryList()) {
         if (fileName.endsWith(QStringLiteral("pdf"))) {
             qDebug() << "Doing" << fileName.toLatin1().data() << ":";
-            Poppler::Document *doc = Poppler::Document::load(directory.canonicalPath() + "/" + fileName);
+            std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(directory.canonicalPath() + "/" + fileName);
             if (!doc) {
                 qWarning() << "doc not loaded";
             } else if (doc->isLocked()) {
                 if (!doc->unlock("", "password")) {
                     qWarning() << "couldn't unlock document";
-                    delete doc;
                 }
             } else {
                 int major = 0, minor = 0;
@@ -48,16 +47,14 @@ int main(int argc, char **argv)
                 doc->pageMode();
 
                 for (int index = 0; index < doc->numPages(); ++index) {
-                    Poppler::Page *page = doc->page(index);
+                    std::unique_ptr<Poppler::Page> page = doc->page(index);
                     page->renderToImage();
                     page->pageSize();
                     page->orientation();
-                    delete page;
                     std::cout << ".";
                     std::cout.flush();
                 }
                 std::cout << std::endl;
-                delete doc;
             }
         }
     }
diff --git a/qt6/tests/stress-poppler-qt6.cpp b/qt6/tests/stress-poppler-qt6.cpp
index 010e4e84..2f6c9026 100644
--- a/qt6/tests/stress-poppler-qt6.cpp
+++ b/qt6/tests/stress-poppler-qt6.cpp
@@ -32,7 +32,7 @@ int main(int argc, char **argv)
         } else {
             QString path = "./pdfdb/" + subdir + "/data.pdf";
             std::cout << "Doing " << path.toLatin1().data() << " :";
-            Poppler::Document *doc = Poppler::Document::load(path);
+            std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(path);
             if (!doc) {
                 qWarning() << "doc not loaded";
             } else {
@@ -56,16 +56,14 @@ int main(int argc, char **argv)
                 doc->pageMode();
 
                 for (int index = 0; index < doc->numPages(); ++index) {
-                    Poppler::Page *page = doc->page(index);
+                    std::unique_ptr<Poppler::Page> page = doc->page(index);
                     page->renderToImage();
                     page->pageSize();
                     page->orientation();
-                    delete page;
                     std::cout << ".";
                     std::cout.flush();
                 }
                 std::cout << std::endl;
-                delete doc;
             }
         }
     }
diff --git a/qt6/tests/stress-threads-qt6.cpp b/qt6/tests/stress-threads-qt6.cpp
index 9f9734d6..d88b20f4 100644
--- a/qt6/tests/stress-threads-qt6.cpp
+++ b/qt6/tests/stress-threads-qt6.cpp
@@ -27,7 +27,7 @@ public:
 
 private:
     Poppler::Document *m_document;
-    QVector<Poppler::Page *> m_pages;
+    std::vector<std::unique_ptr<Poppler::Page>> m_pages;
 };
 
 class CrazyThread : public QThread
@@ -43,9 +43,9 @@ private:
     QMutex *m_annotationMutex;
 };
 
-static Poppler::Page *loadPage(Poppler::Document *document, int index)
+static std::unique_ptr<Poppler::Page> loadPage(Poppler::Document *document, int index)
 {
-    Poppler::Page *page = document->page(index);
+    std::unique_ptr<Poppler::Page> page = document->page(index);
 
     if (page == nullptr) {
         qDebug() << "!Document::page";
@@ -56,7 +56,7 @@ static Poppler::Page *loadPage(Poppler::Document *document, int index)
     return page;
 }
 
-static Poppler::Page *loadRandomPage(Poppler::Document *document)
+static std::unique_ptr<Poppler::Page> loadRandomPage(Poppler::Document *document)
 {
     return loadPage(document, QRandomGenerator::global()->bounded(document->numPages()));
 }
@@ -66,14 +66,14 @@ SillyThread::SillyThread(Poppler::Document *document, QObject *parent) : QThread
     m_pages.reserve(m_document->numPages());
 
     for (int index = 0; index < m_document->numPages(); ++index) {
-        m_pages.append(loadPage(m_document, index));
+        m_pages.push_back(loadPage(m_document, index));
     }
 }
 
 void SillyThread::run()
 {
     forever {
-        foreach (Poppler::Page *page, m_pages) {
+        for (std::unique_ptr<Poppler::Page> &page : m_pages) {
             QImage image = page->renderToImage();
 
             if (image.isNull()) {
@@ -89,7 +89,7 @@ CrazyThread::CrazyThread(Poppler::Document *document, QMutex *annotationMutex, Q
 
 void CrazyThread::run()
 {
-    typedef QScopedPointer<Poppler::Page> PagePointer;
+    typedef std::unique_ptr<Poppler::Page> PagePointer;
 
     forever {
         if (QRandomGenerator::global()->bounded(2) == 0) {
@@ -109,9 +109,7 @@ void CrazyThread::run()
 
             PagePointer page(loadRandomPage(m_document));
 
-            QList<Poppler::Link *> links = page->links();
-
-            qDeleteAll(links);
+            std::vector<std::unique_ptr<Poppler::Link>> links = page->links();
         }
 
         if (QRandomGenerator::global()->bounded(2) == 0) {
@@ -119,9 +117,7 @@ void CrazyThread::run()
 
             PagePointer page(loadRandomPage(m_document));
 
-            QList<Poppler::FormField *> formFields = page->formFields();
-
-            qDeleteAll(formFields);
+            std::vector<std::unique_ptr<Poppler::FormField>> formFields = page->formFields();
         }
 
         if (QRandomGenerator::global()->bounded(2) == 0) {
@@ -176,9 +172,9 @@ void CrazyThread::run()
             for (int index = 0; index < m_document->numPages(); ++index) {
                 PagePointer page(loadPage(m_document, index));
 
-                QList<Poppler::Annotation *> annotations = page->annotations();
+                std::vector<std::unique_ptr<Poppler::Annotation>> annotations = page->annotations();
 
-                if (!annotations.isEmpty()) {
+                if (!annotations.empty()) {
                     qDebug() << "modify annotation...";
 
                     // size is now a qsizetype which confuses bounded(), pretend we will never have that many annotations anyway
@@ -190,9 +186,7 @@ void CrazyThread::run()
                     annotations.at(QRandomGenerator::global()->bounded(annotationsSize))->setModificationDate(QDateTime::currentDateTime());
                 }
 
-                qDeleteAll(annotations);
-
-                if (!annotations.isEmpty()) {
+                if (!annotations.empty()) {
                     break;
                 }
             }
@@ -204,19 +198,18 @@ void CrazyThread::run()
             for (int index = 0; index < m_document->numPages(); ++index) {
                 PagePointer page(loadPage(m_document, index));
 
-                QList<Poppler::Annotation *> annotations = page->annotations();
+                std::vector<std::unique_ptr<Poppler::Annotation>> annotations = page->annotations();
 
-                if (!annotations.isEmpty()) {
+                if (!annotations.empty()) {
                     qDebug() << "remove annotation...";
 
                     // size is now a qsizetype which confuses bounded(), pretend we will never have that many annotations anyway
                     const quint32 annotationsSize = annotations.size();
-                    page->removeAnnotation(annotations.takeAt(QRandomGenerator::global()->bounded(annotationsSize)));
+                    page->removeAnnotation(annotations[QRandomGenerator::global()->bounded(annotationsSize)].get());
+                    annotations.erase(annotations.begin() + QRandomGenerator::global()->bounded(annotationsSize));
                 }
 
-                qDeleteAll(annotations);
-
-                if (!annotations.isEmpty()) {
+                if (!annotations.empty()) {
                     break;
                 }
             }
@@ -244,7 +237,7 @@ int main(int argc, char **argv)
 
     for (int argi = 4; argi < argc; ++argi) {
         const QString file = QFile::decodeName(argv[argi]);
-        Poppler::Document *document = Poppler::Document::load(file);
+        std::unique_ptr<Poppler::Document> document = Poppler::Document::load(file);
 
         if (document == nullptr) {
             qDebug() << "Could not load" << file;
@@ -257,13 +250,13 @@ int main(int argc, char **argv)
         }
 
         for (int i = 0; i < sillyCount; ++i) {
-            (new SillyThread(document))->start();
+            (new SillyThread(document.get()))->start();
         }
 
         QMutex *annotationMutex = new QMutex();
 
         for (int i = 0; i < crazyCount; ++i) {
-            (new CrazyThread(document, annotationMutex))->start();
+            (new CrazyThread(document.get(), annotationMutex))->start();
         }
     }
 
diff --git a/qt6/tests/test-password-qt6.cpp b/qt6/tests/test-password-qt6.cpp
index 80efd471..befcbdfb 100644
--- a/qt6/tests/test-password-qt6.cpp
+++ b/qt6/tests/test-password-qt6.cpp
@@ -11,7 +11,7 @@ class PDFDisplay : public QWidget // picture display widget
 {
     Q_OBJECT
 public:
-    PDFDisplay(Poppler::Document *d, QWidget *parent = nullptr);
+    PDFDisplay(std::unique_ptr<Poppler::Document> &&d, QWidget *parent = nullptr);
     ~PDFDisplay() override;
 
 protected:
@@ -22,12 +22,12 @@ private:
     void display();
     int m_currentPage;
     QImage image;
-    Poppler::Document *doc;
+    std::unique_ptr<Poppler::Document> doc;
 };
 
-PDFDisplay::PDFDisplay(Poppler::Document *d, QWidget *parent) : QWidget(parent)
+PDFDisplay::PDFDisplay(std::unique_ptr<Poppler::Document> &&d, QWidget *parent) : QWidget(parent)
 {
-    doc = d;
+    doc = std::move(d);
     m_currentPage = 0;
     display();
 }
@@ -35,22 +35,18 @@ PDFDisplay::PDFDisplay(Poppler::Document *d, QWidget *parent) : QWidget(parent)
 void PDFDisplay::display()
 {
     if (doc) {
-        Poppler::Page *page = doc->page(m_currentPage);
+        std::unique_ptr<Poppler::Page> page = doc->page(m_currentPage);
         if (page) {
             qDebug() << "Displaying page: " << m_currentPage;
             image = page->renderToImage();
             update();
-            delete page;
         }
     } else {
         qWarning() << "doc not loaded";
     }
 }
 
-PDFDisplay::~PDFDisplay()
-{
-    delete doc;
-}
+PDFDisplay::~PDFDisplay() { }
 
 void PDFDisplay::paintEvent(QPaintEvent *e)
 {
@@ -88,7 +84,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(argv[2], argv[1]);
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[2], argv[1]);
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -119,10 +115,10 @@ int main(int argc, char **argv)
         fontNameList += font.name();
     qDebug() << "          Fonts: " << fontNameList.join(QStringLiteral(", "));
 
-    Poppler::Page *page = doc->page(0);
+    std::unique_ptr<Poppler::Page> page = doc->page(0);
     qDebug() << "    Page 1 size: " << page->pageSize().width() / 72 << "inches x " << page->pageSize().height() / 72 << "inches";
 
-    PDFDisplay test(doc); // create picture display
+    PDFDisplay test(std::move(doc)); // create picture display
     test.setWindowTitle(QStringLiteral("Poppler-Qt6 Test"));
     test.show(); // show it
 
diff --git a/qt6/tests/test-poppler-qt6.cpp b/qt6/tests/test-poppler-qt6.cpp
index be5b1027..3c90232f 100644
--- a/qt6/tests/test-poppler-qt6.cpp
+++ b/qt6/tests/test-poppler-qt6.cpp
@@ -15,7 +15,7 @@ class PDFDisplay : public QWidget // picture display widget
 {
     Q_OBJECT
 public:
-    PDFDisplay(Poppler::Document *d, bool qpainter, QWidget *parent = nullptr);
+    PDFDisplay(std::unique_ptr<Poppler::Document> &&d, bool qpainter, QWidget *parent = nullptr);
     ~PDFDisplay() override;
     void setShowTextRects(bool show);
     void display();
@@ -28,16 +28,16 @@ protected:
 private:
     int m_currentPage;
     QImage image;
-    Poppler::Document *doc;
+    std::unique_ptr<Poppler::Document> doc;
     QString backendString;
     bool showTextRects;
-    QList<Poppler::TextBox *> textRects;
+    std::vector<std::unique_ptr<Poppler::TextBox>> textRects;
 };
 
-PDFDisplay::PDFDisplay(Poppler::Document *d, bool qpainter, QWidget *parent) : QWidget(parent)
+PDFDisplay::PDFDisplay(std::unique_ptr<Poppler::Document> &&d, bool qpainter, QWidget *parent) : QWidget(parent)
 {
     showTextRects = false;
-    doc = d;
+    doc = std::move(d);
     m_currentPage = 0;
     if (qpainter) {
         backendString = QStringLiteral("QPainter");
@@ -58,35 +58,29 @@ void PDFDisplay::setShowTextRects(bool show)
 void PDFDisplay::display()
 {
     if (doc) {
-        Poppler::Page *page = doc->page(m_currentPage);
+        std::unique_ptr<Poppler::Page> page = doc->page(m_currentPage);
         if (page) {
             qDebug() << "Displaying page using" << backendString << "backend: " << m_currentPage;
             QTime t = QTime::currentTime();
             image = page->renderToImage();
             qDebug() << "Rendering took" << t.msecsTo(QTime::currentTime()) << "msecs";
-            qDeleteAll(textRects);
             if (showTextRects) {
                 QPainter painter(&image);
                 painter.setPen(Qt::red);
                 textRects = page->textList();
-                foreach (Poppler::TextBox *tb, textRects) {
+                for (const std::unique_ptr<Poppler::TextBox> &tb : textRects) {
                     painter.drawRect(tb->boundingBox());
                 }
             } else
                 textRects.clear();
             update();
-            delete page;
         }
     } else {
         qWarning() << "doc not loaded";
     }
 }
 
-PDFDisplay::~PDFDisplay()
-{
-    qDeleteAll(textRects);
-    delete doc;
-}
+PDFDisplay::~PDFDisplay() { }
 
 void PDFDisplay::paintEvent(QPaintEvent *e)
 {
@@ -118,7 +112,7 @@ void PDFDisplay::keyPressEvent(QKeyEvent *e)
 void PDFDisplay::mousePressEvent(QMouseEvent *e)
 {
     int i = 0;
-    foreach (Poppler::TextBox *tb, textRects) {
+    for (const std::unique_ptr<Poppler::TextBox> &tb : textRects) {
         if (tb->boundingBox().contains(e->pos())) {
             const QString tt = QStringLiteral("Text: \"%1\"\nIndex in text list: %2").arg(tb->text()).arg(i);
             QToolTip::showText(e->globalPosition().toPoint(), tt, this);
@@ -138,7 +132,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(QFile::decodeName(argv[1]));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QFile::decodeName(argv[1]));
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -182,22 +176,20 @@ int main(int argc, char **argv)
     }
 
     if (doc->numPages() <= 0) {
-        delete doc;
         qDebug() << "Doc has no pages";
         return 0;
     }
 
     {
-        Poppler::Page *page = doc->page(0);
+        std::unique_ptr<Poppler::Page> page = doc->page(0);
         if (page) {
             qDebug() << "Page 1 size: " << page->pageSize().width() / 72 << "inches x " << page->pageSize().height() / 72 << "inches";
-            delete page;
         }
     }
 
     if (argc == 2 || (argc == 3 && strcmp(argv[2], "-qpainter") == 0) || (argc == 3 && strcmp(argv[2], "-textRects") == 0)) {
         bool useQPainter = (argc == 3 && strcmp(argv[2], "-qpainter") == 0);
-        PDFDisplay test(doc, useQPainter); // create picture display
+        PDFDisplay test(std::move(doc), useQPainter); // create picture display
         test.setWindowTitle(QStringLiteral("Poppler-Qt6 Test"));
         test.setShowTextRects(argc == 3 && strcmp(argv[2], "-textRects") == 0);
         test.display();
@@ -205,12 +197,10 @@ int main(int argc, char **argv)
 
         return a.exec(); // start event loop
     } else {
-        Poppler::Page *page = doc->page(0);
+        std::unique_ptr<Poppler::Page> page = doc->page(0);
 
         QLabel *l = new QLabel(page->text(QRectF()), nullptr);
         l->show();
-        delete page;
-        delete doc;
         return a.exec();
     }
 }
diff --git a/qt6/tests/test-render-to-file.cpp b/qt6/tests/test-render-to-file.cpp
index 08063c3d..a60e6c5e 100644
--- a/qt6/tests/test-render-to-file.cpp
+++ b/qt6/tests/test-render-to-file.cpp
@@ -15,7 +15,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    Poppler::Document *doc = Poppler::Document::load(QFile::decodeName(argv[1]));
+    std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QFile::decodeName(argv[1]));
     if (!doc) {
         qWarning() << "doc not loaded";
         exit(1);
@@ -27,7 +27,6 @@ int main(int argc, char **argv)
     }
 
     if (doc->numPages() <= 0) {
-        delete doc;
         qDebug() << "Doc has no pages";
         return 0;
     }
@@ -44,14 +43,13 @@ int main(int argc, char **argv)
     doc->setRenderHint(Poppler::Document::TextAntialiasing, true);
 
     for (int i = 0; i < doc->numPages(); ++i) {
-        Poppler::Page *page = doc->page(i);
+        std::unique_ptr<Poppler::Page> page = doc->page(i);
         if (page) {
             qDebug() << "Rendering page using" << backendString << "backend: " << i;
             QTime t = QTime::currentTime();
             QImage image = page->renderToImage();
             qDebug() << "Rendering took" << t.msecsTo(QTime::currentTime()) << "msecs";
             image.save(QStringLiteral("test-render-to-file%1.png").arg(i));
-            delete page;
         }
     }
 


More information about the poppler mailing list