Qt:使用 poppler 库打开 qrc pdf
我在使用 poppler 库显示 pdf 的功能时遇到了一些问题。下面的代码是出现问题的函数。
const QString &file 是文件的路径 int page是它必须打开的页面
当我将文件设置为真实路径(例如“/Users/User/Documents/xxx.pdf”)时,打开它是没有问题的。但是当我给出 qrc 文件的路径(“:/files/xxx.pdf”)时,它不起作用。我想用它来显示用户手册,例如在应用程序中。
我还尝试首先用它制作一个 QFile,打开它并执行 readAll,然后加载通过执行 Poppler::Document::loadFromData(the qbytearray)
收到的 QByteArray,但是当它以只读模式打开 QFile。
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'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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完美读取资源中的所有数据,已检查。所以我建议你在尝试时做错了什么。也许是路径错误,也许是其他原因......
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...