我正在尝试使用 Okular 库和 Qt4.8 创建一个 pdf 阅读器。我在打开 pdf 时遇到问题,不确定为什么openDocumentArchive()
无法设置传入的网址,而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寻求帮助。