PDA

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



karankumar1609
11th March 2013, 06: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
)
)
);

filePath is normal file path with native seperators:
"C:/a.jpg"

please help if you have any idea about that.

anda_skoa
11th March 2013, 14: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.

Cheers,
_

karankumar1609
12th March 2013, 04: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.

ChrisW67
12th March 2013, 07:07
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.

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



if(!QDesktopServices::openUrl(
QUrl::fromLocalFile(
QString(
filePath
)
)
)
) {
QMessageBox::information(this,
tr("View document"),
tr("Unable to find proper viewer for document"),
QMessageBox::Ok);
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.

ChrisW67
25th March 2013, 22: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.