Results 1 to 4 of 4

Thread: open an external file in default app from my OS

  1. #1
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default open an external file in default app from my OS

    Hello,

    I'm sorry for ask something basic like this, but i searched all day and nor sure how do it...

    there are any way to open an external file in default app from my OS?

    eg:
    Qt Code:
    1. QString s = qApp->applicationDirPath() + QDir::toNativeSeparators("/PDF_file.pdf");
    2. s.open();
    3. // or
    4. s.execute();
    To copy to clipboard, switch view to plain text mode 

    many thanks!
    Juliano

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

    Default Re: open an external file in default app from my OS


  3. #3
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: open an external file in default app from my OS

    Quote Originally Posted by ChrisW67 View Post
    So many thanks! Solved on linux

    my code will work on windows too?

    Qt Code:
    1. #include <QDir>
    2. #include <QUrl>
    3. #include <QDesktopServices>
    4.  
    5. void MainWindow::on_action_openfile_triggered()
    6. {
    7. QString s = qApp->applicationDirPath() + QDir::toNativeSeparators("/pdf_file.pdf");
    8. QDesktopServices::openUrl(QUrl::fromLocalFile(s));
    9. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,620
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: open an external file in default app from my OS

    It should work as long as the desktop shell has an association between the PDF extension and a reader. Not sure what happens if no association exists.

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2013, 00:34
  2. Open an in-memory file with the default system application
    By berzasnon in forum Qt Programming
    Replies: 8
    Last Post: 7th October 2012, 17:03
  3. Replies: 2
    Last Post: 5th August 2010, 10:18
  4. Open an external file from qt
    By maider in forum Qt Programming
    Replies: 9
    Last Post: 12th March 2010, 10:09
  5. How to open a HTML-file with the default webbrowser?
    By Teuniz in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2007, 11:58

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.