0

I'm trying to run Evince to read a pdf file from my Qt program, using QProcess::startDetached method :

QProcess myProcess = QProcess();
myProcess.startDetached("evince", "~/mypath/doc.pdf");

Evince is well launched, but in its HMI I get the message "Cannot open the file, No such file or directory"

But the path is ok as when I use "acroread" to read the file, it finds the file and can open it.

Thank you for helping :)

3 Answers3

0

Have you tried to send full path /home/user/mypath/doc.pdf?

Try also to call it with one parameter:

myProcess.startDetached("evince ~/mypath/doc.pdf");
0

I remember I had the same problem and couldn't make it work. However this worked for me:

QString commandLine = command + " " + parameter;
int result = QProcess::execute(commandLine.toLatin1());
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
0

The tilde character is a shell shortcut, it doesn't necessarily mean anything for any other program.

For a shell it means the equivalent of $HOME. acrocread might be a shell script and implicitly expand the argument before launching the actual application, evince is probably the program itself so you'll have to expand that yourself.

E.g.

QDir homeDir = QDir::home();
QFileInfo fileInfo(homeDir, "mypath/doc.pdf");

QProcess::startDetached("evince", QStringList() << fileInfo.absoluteFilePath());

If you want to open the PDF in the user's reader of choice, see QDesktopServices::openUrl() instead.

Kevin Krammer
  • 5,159
  • 2
  • 9
  • 22