Okular openDocumentArchive () не может открыть PDF-файлы - PullRequest
2 голосов
/ 16 марта 2019

Проблема

Я пытаюсь создать pdf читатель с Okular библиотекой и Qt4.8 .У меня проблема с открытием pdf , и я не уверен, почему openDocumentArchive() не может установить переданный URL, а currentDocument() возвращает KUrl("") (см. Мой код):

Код

#include "mainwindow.h"
#include <QApplication>
#include <QString>
#include <QDebug>
#include <QUrl>
#include <okular/core/document.h>
#include <okular/core/settings_core.h>

using namespace Okular;

class PdfViewer : public Document
{

public:
    QUrl url;
    QString filename;

    PdfViewer (QString pf, QUrl pu): Document(new QWidget()) {    
        filename = pf;
        url = pu;
    }
    void pdfReader();
};

void PdfViewer::pdfReader(){
    OpenResult a =  openDocumentArchive(filename, url); // returns a = 1 {OpenError}
    qDebug() << currentDocument();  // returns KUrl("")
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    SettingsCore::instance("");
    QString fn = "e.pdf";
    QUrl fu("/home/png/Desktop/e.pdf");
    PdfViewer view (fn, fu.path());
    view.pdfReader();

    return 0;
}

openDocumentArchive:

Document::OpenResult Document::openDocumentArchive( const QString & docFile, const QUrl & url, const QString & password )
  {
      d->m_archiveData = DocumentPrivate::unpackDocumentArchive( docFile );
      if ( !d->m_archiveData )
          return OpenError;

      const QString tempFileName = d->m_archiveData->document.fileName();
      QMimeDatabase db;
      const QMimeType docMime = db.mimeTypeForFile( tempFileName, QMimeDatabase::MatchExtension );
      const OpenResult ret = openDocument( tempFileName, url, docMime, password );

      if ( ret != OpenSuccess )
      {
          delete d->m_archiveData;
          d->m_archiveData = nullptr;
      }

      return ret;
  }

Я использую Okular Documentation для помощи.

...