1
votes

I'm having a bit of trouble with my function for displaying pdf's with the poppler library. The code below is the function in which the problem occurs.

const QString &file is the path to the file int page is the page on which it has to open

When i set file to a real path (e.g. "/Users/User/Documents/xxx.pdf"), it is no problem to open it. But when i give the path to a qrc file (":/files/xxx.pdf"), it won't work. I want to use it for displaying a user manual for instance, within the application.

I've also tried first making a QFile out of it, opening it and doing readAll, then loading the QByteArray received by doingPoppler::Document::loadFromData(the qbytearray), but it errors already when opening the QFile in ReadOnly mode.

void class::setPdf(const QString &file, int page)
{
    Poppler::Document *doc = Poppler::Document::load(file);
    if (!doc) {
        QMessageBox msgbox(QMessageBox::Critical, tr("Open Error"), tr("Please check preferences: cannot open:\n") + file,
                         QMessageBox::Ok, this);
        msgbox.exec();
    }
    else{ /*Code for displaying the pdf, which works fine*/
    }
}

I hope you can help me,

greetings,

Matt

1
How had you opened it with QFile? Normally, QFile reads resources from qrc in readOnly mode without any troubles...Raiv

1 Answers

1
votes

I've also tried first making a QFile out of it, opening it and doing readAll, then loading the QByteArray received by doingPoppler::Document::loadFromData(the qbytearray), but it errors already when opening the QFile in ReadOnly mode.

QFile f;
f.setFileName(":/skin/AppIcon16.png");
f.open(QIODevice::ReadOnly);
QByteArray r=f.readAll();

Perfectly reads all data from the resource, have checked it. So i suggest you did something wrong when tried that. Maybe path errors, maybe something else...