PDA

View Full Version : Open an external file from qt



maider
12th March 2010, 10:03
Hello,

I'm trying to open a .pdf file from qt. I have develop the following code to achieve my goal:


#include <QDesktopServices>
#include <QUrl>

exercise::exercise(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.open,SIGNAL(clicked()),this,SLOT(openDo cument()));
}

exercise::~exercise()
{

}

void exercise::openDocument()
{
QDesktopServices desk;
desk.openUrl(QUrl("file://C:/a.pdf"));
}


Can someone help me? i have read the post about this thread, but i'm not capable to solve the problem.

wysota
12th March 2010, 10:06
Ok, but what exactly is the problem?

BTW. Take a look at QUrl::fromLocalFile()

maider
12th March 2010, 10:08
the problem is that when I pushed the button no file has shown.

maider
12th March 2010, 10:24
i have get it!

but is any function in qt to open a pdf without havin installing into my software the adobe reader?

aamer4yu
12th March 2010, 10:34
I dont think so.. though I guess there are 3rd party libraries to do that

wysota
12th March 2010, 10:35
There is poppler but I don't know if it supports Windows.

toutarrive
12th March 2010, 10:37
Qt is not shipped with a pdf viewer, so to view pdf files:
you can embed adobe ActiveX control in your app,
or fires up the adobe reader ,
or use some third parties libraries (Poppler is the most known).

maider
12th March 2010, 10:52
ok, i will try with poppler.

one question more please! Nowadays I want to see the .pdf into a text edit but problems occured. why? i have written this comand:
ui.textEdit->desk.openUrl(QUrl("a.pdf"));

thanks

wysota
12th March 2010, 10:59
This is not even a proper C++ syntax... And even if it was, you can't expect an application framework to do everything you could imagine it would be good to have. You can't place PDF files into QTextEdit. Please launch Qt Assistant, type in "QDesktopServices" in the index tab and read the description of what the class does.

maider
12th March 2010, 11:09
you are right! i cannot use it-