Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Okular openDocumentArchive()无法打开pdf文件 问题_C++_Qt_Pdf_Qt4.8_Okular - Fatal编程技术网

C++ Okular openDocumentArchive()无法打开pdf文件 问题

C++ Okular openDocumentArchive()无法打开pdf文件 问题,c++,qt,pdf,qt4.8,okular,C++,Qt,Pdf,Qt4.8,Okular,我正在尝试使用okula库和Qt4.8制作一个pdf阅读器。我在打开pdf时遇到问题,不确定为什么openDocumentArchive()无法设置传入的url,并且currentDocument()返回KUrl(“”)(请查看我的代码): 代码 我正在使用以寻求帮助。我更新了我的问题。我认为这是由于qt版本或pdf文件损坏造成的问题。 #include "mainwindow.h" #include <QApplication> #include <QString> #

我正在尝试使用okula库和Qt4.8制作一个pdf阅读器。我在打开pdf时遇到问题,不确定为什么
openDocumentArchive()
无法设置传入的url,并且
currentDocument()
返回
KUrl(“”
)(请查看我的代码):

代码
我正在使用以寻求帮助。

我更新了我的问题。我认为这是由于qt版本或pdf文件损坏造成的问题。
#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;
}
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;
  }