Results 1 to 6 of 6

Thread: open a document

  1. #1
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default open a document

    hi.
    I would like to know if it possible to openb a document ( exp. pdf ) from a Qt application.
    for example when the user click on an action (help action) a file.pdf( documentation ) should be opened..??
    I tried with QProcess but I didnt get a result:

    Qt Code:
    1. QProcess myprocess;
    2. QString app="//path/file.pdf";
    3. myprocess.start(app);
    To copy to clipboard, switch view to plain text mode 

    please if some one could help!!
    Last edited by jpn; 29th June 2008 at 15:23. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: open a document

    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: open a document

    thanks ..
    I tried the code:


    Qt Code:
    1. desk.openUrl(QUrl::fromLocalFile("test.pdf"));
    To copy to clipboard, switch view to plain text mode 


    but it doesnt open anythg..

    test.pdf is in the same directory as the .exe .. but it doesnt work??

    I dont know where is the error
    Last edited by jpn; 29th June 2008 at 19:30. Reason: missing [code] tags

  4. #4
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: open a document

    Oki I found it:
    I used only
    Qt Code:
    1. desc.openUrl(QUrl("test.pdf"));
    To copy to clipboard, switch view to plain text mode 
    it works!!
    thanks for help
    Last edited by jpn; 30th June 2008 at 05:43. Reason: missing [code] tags

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: open a document

    First of all, allocating an instance of QDesktopServices is pointless because QDesktopServices::openUrl() is a static method. QUrl::fromLocalFile("test.pdf") won't work because it would correspond to "file:///test.pdf".
    J-P Nurmi

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open a document

    I use this way and run any time on each fullpath url

    Qt Code:
    1. /* tr macro on no Q_OBJECT class !!!! */
    2. static inline void OpenDesk( QUrl loc )
    3. {
    4. #if defined Q_WS_MAC
    5. /* direct to open */
    6. QProcess *m = new QProcess();
    7. macs << loc.toString();
    8. m->startDetached(QString("open") , macs );
    9. return;
    10. #endif
    11.  
    12. #if defined Q_WS_WIN
    13. QString fullFileName = loc.toString();
    14.  
    15. if (fullFileName.startsWith("http://", Qt::CaseInsensitive) ||
    16. fullFileName.startsWith("https://", Qt::CaseInsensitive) ||
    17. fullFileName.startsWith("ftp://", Qt::CaseInsensitive) ||
    18. fullFileName.startsWith("news://", Qt::CaseInsensitive) ||
    19. fullFileName.startsWith("mailto:", Qt::CaseInsensitive) ||
    20. fullFileName.startsWith("webdav://", Qt::CaseInsensitive) )
    21. {
    22.  
    23. } else {
    24. fullFileName.prepend("file:///"); /* or qurl to localfile */
    25. }
    26. bool wr = QDesktopServices::openUrl(QUrl(fullFileName));
    27. if (!wr) {
    28. QMessageBox::warning(0,QString("Error"),
    29. QString("Window Unable to open action file or dir %1").arg(loc.toString()));
    30. }
    31. return;
    32. #endif
    33. /* linux */
    34. bool r = QDesktopServices::openUrl(loc);
    35. if (!r) {
    36. QMessageBox::warning(0,QString("Error"),
    37. QString("Linux Unable to open action file or dir %1").arg(loc.toString()));
    38. }
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 7th October 2015, 19:43
  2. QTextBrowser: Cannot open
    By veda in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2007, 12:05
  3. can Qt open MS word document?
    By coder1985 in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2007, 14:34
  4. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 11
    Last Post: 1st February 2007, 07:03
  5. How to open a document with the default application?
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 30th April 2006, 08:47

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.