PDA

View Full Version : Qurl+poppler



wakitowaki
15th June 2011, 13:41
hi to all.
This is my first post so i hope that this is the right section.
I'm going to post a little portion of my code and a fter i'll go to expose my problem


pdfviewer.h:



#ifndef PDFVIEWER_H
#define PDFVIEWER_H

#include <QMainWindow>
#include <QImage>
#include <QVector>
#include <iostream>
#include <poppler/qt4/poppler-qt4.h>
#include <QFileDialog>


namespace Ui {
class PdfViewer;
}

class PdfViewer : public QMainWindow
{
Q_OBJECT

public:
explicit PdfViewer(QString, QWidget *parent = 0);
~PdfViewer();
bool setDocument(const QString &filePath);
void showPage(int page);
int getCurrentPage();
void setScale(double scaleFactor = 1.0);

private slots:
void on_indietroBtn_clicked();
void on_avantiBtn_clicked();
void on_comboBox_currentIndexChanged(int index);

void on_lineEdit_returnPressed();

private:
Ui::PdfViewer *ui;
int currentPage;
Poppler::Document *doc;
double scaleFactor;
QVector<qreal> scaleFactors;

};

#endif // PDFVIEWER_H



mainwindow.cpp:




....................

QString filePath = model->record(index.row()).value("path").toString();
PdfViewer *pdfViewer = new PdfViewer(filePath, 0);
pdfViewer->show();

....................



whit this code i can open a pdf from a path to a local file.now i have this url

http://www.ing.unisi.it/didattica/matdid/2163.pdf

which is a pdf itself.Can i open directly this file by passing it's URL to PdfViewer?
i've tried this



QUrl url("http://www.ing.unisi.it/didattica/matdid/2162.pdf");
QString filePath = url.path();
PdfViewer *pdfViewer = new PdfViewer(filePath, 0);
pdfViewer->show();


but it doesn't work

error:


Error: Cannot open the specified file
Couldn't open file '/didattica/matdid/2162.pdf': File or directory not exist.


thank to all for the replies and i want to say sorry for my bad english.

wysota
15th June 2011, 19:39
You need to download the file first. You can use QNetworkAccessManager for that.