PDA

View Full Version : applicationDirPath() issue with the windows "program files" directory



john_god
13th November 2010, 11:58
Hi guys

I'm trying to launch a html file from my app:


QString path = QApplication::applicationDirPath();
QString str = path +tr("/mat_html/mat_manual_en.html");

if ( ! QDesktopServices::openUrl(QUrl( str, QUrl::TolerantMode )) )
QMessageBox::about(0,tr("Error"),tr("Error. Help file not found")+"\n"+str);

So far so good, it work's on several directorys, except for the "program files" windows directory.

It seems the portuguese windows version creates some kind of simbolic link directory where in my explorer the file.exe directory is "c:/programas/math graphica", but in command line and the str output is "c:/program files/math graphica".

so I tried a hardcoded version wich still doens't work:


QString str = path +tr("/mat_html/mat_manual_en.html");
QString str2 = "C:/Program Files/Math Graphica"+tr("/mat_html/mat_manual_en.html");
str2 = "C:/Programas/Math Graphica"+tr("/mat_html/mat_manual_en.html");

if ( ! QDesktopServices::openUrl(QUrl( str )) &&
! QDesktopServices::openUrl(QUrl( str2 , QUrl::TolerantMode)) )
QMessageBox::about(0,tr("Error"),tr("Error. Help file not found")+"\n"+str);

So I'm running out of ideias :confused:

ChrisW67
14th November 2010, 02:11
Convert the file path to a valid file: URL as in the QDesktopServices docs example:


QString path = QString("file:///%1/%2")
.arg(QApplication::applicationDirPath())
.arg("mat_html/mat_manual_en.html");
QDesktopServices::openUrl(QUrl(path, QUrl::TolerantMode));

john_god
14th November 2010, 11:14
Thanks ChrisW67, you made my day. :)