[SOLVED]Open file with it default program
-
wrote on 28 Mar 2014, 15:24 last edited by
Hi guys...
I need to open a file with it default program defined in the OS.
I'm doing this to open a pdf:
@qDebug() << QDesktopServices::openUrl(QUrl("file:///home/freddy/unordered.pdf", QUrl::TolerantMode));@
and my program crash it . I test with this code too:
@qDebug() << QDesktopServices::openUrl(QUrl("/home/freddy/unordered.pdf", QUrl::TolerantMode));@
and
@qDebug() << QDesktopServices::openUrl(QUrl("file:///home/freddy/unordered.pdf"));@
and the result is the same:
@The program has unexpectedly finished.@
I'm using Qt5.2.1 in Archlinux, but my app will run over Mac and Windows too,any advice please ?? thanks !!!
best regards
-
Hi,
Can you try building your url using "fromLocalFile":http://qt-project.org/doc/qt-5/qurl.html#fromLocalFile ?
-
wrote on 28 Mar 2014, 16:51 last edited by
Hi SGaist !!! thanks for answer !!!
I had try:
@qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("file:///home/freddy/unordered.pdf"));@but the program stil crash it !!!
-
wrote on 28 Mar 2014, 17:22 last edited by
Works for me on OSX (Qt-5.3-beta) and Ubuntu (Qt-5.2.1)
@
qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("/home/user/tdd.pdf"));
qDebug() << QDesktopServices::openUrl(QUrl("file:///home/user/GUIdesign.pdf", QUrl::TolerantMode));
@Do you have a core file? Could you post a backtrace log here.
You don't need to add "file://" if you use @QUrl::fromLocalFile(...)@
-
wrote on 28 Mar 2014, 17:30 last edited by
yes...
my core file is only:
@
#include <QDesktopServices>int main()
{
qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("file:///home/user/unordered.pdf"));
return 0;
}
@and the backtrace log just tell me
@Starting /home/freddy/Trabajo/bpg/andy&pedro/proyecto/build-adviser-Clang-Debug/adviser...
QML debugging is enabled. Only use this in a safe environment.
The program has unexpectedly finished.
/home/freddy/Trabajo/bpg/andy&pedro/proyecto/build-adviser-Clang-Debug/adviser crashed@ -
wrote on 28 Mar 2014, 18:08 last edited by
You need to initialize QApplication in order in use QDesktopServices
Try this
@
#include <QApplication>
#include <QDebug>
#include <QUrl>
#include <QDesktopServices>int main(int argc, char *argv[])
{
QApplication a(argc, argv);qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("/home/user/tdd.pdf")); qDebug() << QDesktopServices::openUrl(QUrl("file:///home/user/GUIdesign.pdf", QUrl::TolerantMode)); return 0;
}
@
-
wrote on 28 Mar 2014, 18:14 last edited by
That right andreyc
Thank you for your help guys !!!
It's work !!!
-
wrote on 2 Aug 2014, 00:12 last edited by
@ QString str(QDir::currentPath());
str.append("/ManualUsuario.pdf");
QDesktopServices::openUrl(QUrl::fromLocalFile(str));@