Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPdfBookmarkModel return -1 as page number

QPdfBookmarkModel return -1 as page number

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 233 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VincNRC
    wrote on last edited by
    #1

    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);
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved