View Full Version : QDesktopServices not opened jpg files on other's PC

11th March 2013, 07:50
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.

QDesktopServices::openUrl(QUrl::fromLocalFile(QStr ing(

filePath is normal file path with native seperators:

please help if you have any idea about that.

11th March 2013, 15:41
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.


12th March 2013, 05:26
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.

// "D:/POC/trunk/desktopapp/TouchDox/build/product/TempData/Data.jpg"
QUrl( "file:///D:/POC/trunk/desktopapp/TouchDox/build/product/TempData/Data.jpg" )

above is the path of my jpg file.

12th March 2013, 08:07
filePath is normal file path with native seperators:

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.

25th March 2013, 14:40
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".

) {
tr("View document"),
tr("Unable to find proper viewer for document"),
qDebug()<<"Unable to open document";

} else {
qDebug()<<"document opened successfully";

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.

25th March 2013, 23:52
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 (http://msdn.microsoft.com/en-us/library/bb773471.aspx) with ASSOCSTR_EXECUTABLE to see if there is an associated program.