Results 1 to 6 of 6

Thread: QDesktopServices not opened jpg files on other's PC

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question QDesktopServices not opened jpg files on other's PC

    hello all,

    i am using QDesktopServices to get open image files.
    Image files got open on my PC but unable to open it on other's PC.

    Qt Code:
    1. QDesktopServices::openUrl(QUrl::fromLocalFile(QString(
    2. filePath
    3. )
    4. )
    5. );
    To copy to clipboard, switch view to plain text mode 
    filePath is normal file path with native seperators:
    "C:/a.jpg"

    please help if you have any idea about that.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices not opened jpg files on other's PC

    Can you try a different data type? Maybe the other user doesn't have a preferred application associated with jpg.

    Might also be worth to check the generated QUrl object, i.e. to see if it is a valid URL and points to the correct file.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDesktopServices not opened jpg files on other's PC

    Hello Admin,

    path of the jpg file is created by the code. and path exists,
    also jog file got saved in that directory, but i dont know it not get open.
    if there is no appropriate application to open jpg(but other pc have it) then it should open an "Open With" box.

    Qt Code:
    1. // "D:/POC/trunk/desktopapp/TouchDox/build/product/TempData/Data.jpg"
    2. QUrl( "file:///D:/POC/trunk/desktopapp/TouchDox/build/product/TempData/Data.jpg" )
    To copy to clipboard, switch view to plain text mode 

    above is the path of my jpg file.

  4. #4
    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: QDesktopServices not opened jpg files on other's PC

    filePath is normal file path with native seperators:
    "C:/a.jpg"
    They are not native separators for a Windows machine, not that this is relevant to the problem.

    Have you bothered to look at the return value from QDesktopServices::openUrl()? QDesktopServices::openUrl() checks QUrl::isValid(); have you checked? After that openUrl() does the same thing as pasting your URL into the Windows Run... box. it calls the Windows API function ShellExecute() and returns false if it fails. If Windows chooses not to do anything in response that is a Windows issue.

  5. #5
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question Re: QDesktopServices not opened jpg files on other's PC

    i have checked everything about the URLs as well as Image plugins.
    Well the issue is the another PC not have any specific image viewer so that QDesktopServices::OpenUrl fails to open jpg files, but it successfully opens other files.
    When i installed the image viewer than ::OpenUrl starts opening the jpg(Image) files.

    well now i want to show an popup when ::OpenUrl fails to open image files.
    but unfortunatly it also return "true".

    Qt Code:
    1. if(!QDesktopServices::openUrl(
    2. QUrl::fromLocalFile(
    3. filePath
    4. )
    5. )
    6. )
    7. ) {
    8. QMessageBox::information(this,
    9. tr("View document"),
    10. tr("Unable to find proper viewer for document"),
    11. qDebug()<<"Unable to open document";
    12.  
    13. } else {
    14. qDebug()<<"document opened successfully";
    15. }
    To copy to clipboard, switch view to plain text mode 

    in the above code qDebug "document opened successfully" shows even is image file not get opened.

    anyone have idea about that?
    Why ::OpenUrl return true even if it not open Image file.

  6. #6
    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: QDesktopServices not opened jpg files on other's PC

    QDesktopServices::openUrl() returns true because the underlying Windows API calls returns success even when Windows displays a "Windows can't open this file" dialog. Qt has no control over what Windows returns.

    If you want you can use Windows API call AssocQueryString with ASSOCSTR_EXECUTABLE to see if there is an associated program.

Similar Threads

  1. Replies: 0
    Last Post: 16th November 2011, 20:57
  2. Replies: 3
    Last Post: 16th September 2011, 05:50
  3. Replies: 1
    Last Post: 3rd February 2010, 04:45
  4. QDesktopServices::openUrl() not opening files in set path
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 18:34
  5. Implementing an "open recently opened files" menu?
    By joelthelion in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2009, 10:49

Tags for this Thread

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.