Results 1 to 5 of 5

Thread: Open file in its standard application, according to file extension

  1. #1
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Open file in its standard application, according to file extension

    Hello,
    I just wanted to to "start" a html file, expecting it to be displayed in the standard browser (Firefox in my case; may be Internet Explorer or anything else on other systems; my application is restricted to Windows systems for other reasons):
    Qt Code:
    1. QString command(QCoreApplication::applicationDirPath() + "/Help/index.html" );
    2. bool success = QProcess::startDetached( command );
    To copy to clipboard, switch view to plain text mode 
    The html file is in the subdirectory "Help" that lies parallel to the executable.

    On Windows systems "starting" a file of any type normally starts the application that is linked to the file extension.
    When trying to use this behaviour with a QProcess it doesn't seem to work.

    Any ideas how I can open a file in its "standard application"?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Open file in its standard application, according to file extension

    take a look at QDesktopServices::openUrl.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Open file in its standard application, according to file extension

    I just found out that the following code will do the job:
    Qt Code:
    1. QDesktopServices::openUrl ( QCoreApplication::applicationDirPath() + "/Help/index.html" );
    To copy to clipboard, switch view to plain text mode 
    I seems to work not only for html files but also for any other files (bmp, txt etc.).

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Open file in its standard application, according to file extension

    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Open file in its standard application, according to file extension

    I will add the fromLocalFile() call. Thanks for the hint.

Similar Threads

  1. QFileDialog and file extension
    By calhal in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2010, 12:54
  2. To open a PDF file in QT Application
    By augusbas in forum Qt Programming
    Replies: 3
    Last Post: 9th February 2010, 09:32
  3. Automatic file extension is not added to saved file on mac os x
    By sanjayshelke in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 06:56
  4. Open pdf file in the standard app system
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 15:34
  5. Open File /w Native Application
    By bpetty in forum Newbie
    Replies: 4
    Last Post: 27th October 2006, 22:19

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.