Results 1 to 3 of 3

Thread: applicationDirPath() issue with the windows "program files" directory

  1. #1
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default applicationDirPath() issue with the windows "program files" directory

    Hi guys

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

    Qt Code:
    1. QString path = QApplication::applicationDirPath();
    2. QString str = path +tr("/mat_html/mat_manual_en.html");
    3.  
    4. if ( ! QDesktopServices::openUrl(QUrl( str, QUrl::TolerantMode )) )
    5. QMessageBox::about(0,tr("Error"),tr("Error. Help file not found")+"\n"+str);
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. QString str = path +tr("/mat_html/mat_manual_en.html");
    2. QString str2 = "C:/Program Files/Math Graphica"+tr("/mat_html/mat_manual_en.html");
    3. str2 = "C:/Programas/Math Graphica"+tr("/mat_html/mat_manual_en.html");
    4.  
    5. if ( ! QDesktopServices::openUrl(QUrl( str )) &&
    6. ! QDesktopServices::openUrl(QUrl( str2 , QUrl::TolerantMode)) )
    7. QMessageBox::about(0,tr("Error"),tr("Error. Help file not found")+"\n"+str);
    To copy to clipboard, switch view to plain text mode 

    So I'm running out of ideias
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: applicationDirPath() issue with the windows "program files" directory

    Convert the file path to a valid file: URL as in the QDesktopServices docs example:
    Qt Code:
    1. QString path = QString("file:///%1/%2")
    2. .arg(QApplication::applicationDirPath())
    3. .arg("mat_html/mat_manual_en.html");
    4. QDesktopServices::openUrl(QUrl(path, QUrl::TolerantMode));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    john_god (14th November 2010)

  4. #3
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: applicationDirPath() issue with the windows "program files" directory

    Thanks ChrisW67, you made my day.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

Similar Threads

  1. Replies: 4
    Last Post: 26th July 2010, 07:02
  2. Absolute Path to users "Program Files" on Windows
    By MisterIKS in forum Qt Programming
    Replies: 6
    Last Post: 5th June 2010, 09:40
  3. Replies: 4
    Last Post: 18th April 2010, 00:37
  4. "Cannot run program "C:\Qt\4.3.3\bin\qmake": file not found
    By PeteH in forum Installation and Deployment
    Replies: 1
    Last Post: 7th February 2009, 00:48
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.