QPdfBookmarkModel return -1 as page number
Unsolved
General and Desktop
-
I'm currently testing using Qtpdf for reading a pdf. I based my code on the exemple from Qt (https://doc.qt.io/qt-5/qtpdf-pdfviewer-example.html)
For some PDF, when selecting a bookmark from the list, the page number returned is -1. Only the 3 or 4 first elements return the correct page number. I tried opening those pdf on my PC and all the bookmarks work fine on this end. What can be the cause of this?
Here is my code
Pieces::Pieces(QWidget *parent) : QWidget(parent), ui(new Ui::Pieces) { ui->setupUi(this); pdfView = new QPdfView(this); m_document = new QPdfDocument(this); m_bookModel = new QPdfBookmarkModel(this); m_document->load(":/pdf/pdf/8923516.pdf"); m_bookModel->setDocument(m_document); pdfView->setDocument(m_document); pdfView->setZoomFactor(pdfView->zoomFactor() / 1.15); ui->layoutPartsPdf->addWidget(pdfView); ui->listViewBookmarks->setModel(m_bookModel); connect(ui->listViewBookmarks, SIGNAL(activated(QModelIndex)), this, SLOT(bookSelected(QModelIndex))); } void Pieces::bookSelected(const QModelIndex &index){ if(!index.isValid()){ return; } const int page = index.data(QPdfBookmarkModel::PageNumberRole).toInt(); ui->label->setText(QString::number(page)); pdfView->pageNavigation()->setCurrentPage(page); }