QDesktopServices open url & local file & pdf or doc
Before QDesktopServices qt4.2 i use this function to open explorer file url & other mailto:xxx ecc....
Code:
/* open file browser explorer finder pdf doc ecc... url mail ecc on other programm */
void Base_Function
::OpenUrl_File_Dir_Dektop( QString item
) {
#if defined(Q_WS_WIN)
s << "url.dll,FileProtocolHandler" << item;
p.
startDetached(QString("rundll32.exe") , s
);
#endif
#if defined Q_WS_MAC
macs << item; /* oeffnet der default browser */
m.
startDetached(QString("open") , macs
);
/* open file weburl .... finder e other */ #endif
}
Now QDesktopServices open only Url http:/..... or mail to ....
& !not open file pdf or doc or other same as up write function....
wath is the location of QDesktopServices to expand this class? and Add other url different as http://
but now QDesktopServices is super to open url on linux.... method "open" exist only on mac...
Code:
#include <QDesktopServices>
#define HOME_DIR_YOUR \
QUrl youhome
(HOME_DIR_YOUR
);
/* filee path not open */ QUrl youhome1
("http://www.qtcentre.org/forum/");
/* running open browser*/
Re: QDesktopServices open url & local file & pdf or doc
Quote:
Originally Posted by
patrik08
Now QDesktopServices open only Url http:/..... or mail to ....
& !not open file pdf or doc or other same as up write function....
Are you sure?
Quote:
bool QDesktopServices::openUrl ( const QUrl & url ) [static]
Opens the given url in the appropriate web browser for the user's desktop environment, and returns true if successful; otherwise returns false.
If the URL is a reference to a local file (i.e. the URL scheme is "file") then it will be opened with a suitable application instead of a web browser.
If a mailto URL is specified, the user's e-mail client will be used to open a composer window containing the options specified in the URL, similar to the way mailto links are handled by a web browser.
Re: QDesktopServices open url & local file & pdf or doc
Quote:
Originally Posted by
jacek
Are you sure?
Oh yes.... i testet on window & Mac .... Tiger qt4.2
Code:
#include <QDesktopServices>
#define HOME_DIR_YOUR \
/* image exist */
QUrl youhome
(HOME_DIR_YOUR
);
/* file path not open */
/* if i use url.dll,FileProtocolHandler win or mac /usr/bin/open filexx GIMP start on win & imageprewiuv on mac */
Re: QDesktopServices open url & local file & pdf or doc
Quote:
Originally Posted by
patrik08
#define HOME_DIR_YOUR \
QString( "%1/ale.png" ).arg( QDir::homePath())
...
QUrl youhome(HOME_DIR_YOUR);
Are you sure this creates a valid QUrl object? What does "youhome.isValid()" return? Shouldn't there be "file://" in front of the string?
Re: QDesktopServices open url & local file & pdf or doc
Quote:
Originally Posted by
jacek
Are you sure this creates a valid QUrl object? What does "youhome.isValid()" return? Shouldn't there be "file://" in front of the string?
Now is running .....
If i write a Qurl class i append this small code..... on return value....
Code:
{
if (fullFileName.startsWith("http://", Qt::CaseInsensitive) or
fullFileName.startsWith("https://", Qt::CaseInsensitive) or
fullFileName.startsWith("ftp://", Qt::CaseInsensitive) or
fullFileName.startsWith("news://", Qt::CaseInsensitive) or
fullFileName.startsWith("mailto:", Qt::CaseInsensitive) or
fullFileName.startsWith("webdav://", Qt::CaseInsensitive) )
{
return fullFileName;
} else {
return fullFileName.prepend("file:///");
}
}
Code:
#include <QDesktopServices>
#define HOME_DIR_YOUR \
qDebug() << "### HOME_DIR_YOUR " << HOME_DIR_YOUR;
QUrl youhome
(HOME_DIR_YOUR.
prepend("file:///"));
/* filee path not open */ qDebug() << "### youhome.toString() " << youhome.toString();
qDebug() << "### youhome.toLocalFile() " << youhome.toLocalFile();
QUrl youhome1
("http://www.qtcentre.org/forum/");
/* running open browser*/
### HOME_DIR_YOUR "C:/Documents and Settings/ppk-it/ale.png"
### youhome.toString() "file:///C:/Documents and Settings/ppk-it/ale.png"
### youhome.toLocalFile() "C:/Documents and Settings/ppk-it/ale.png"
1 Attachment(s)
Re: QDesktopServices open url & local file & pdf or doc
This works for me without any special magic tricks.
Re: QDesktopServices open url & local file & pdf or doc
Hi wysota,
I tried your code snipet and it works fine. The only problem I discovered is that it won't work anymore if there are spaces within the filename or path. I tried to find a workaround but I didn't find anything.
Anybody any ideas?
Re: QDesktopServices open url & local file & pdf or doc
This has to be a valid URL and URL doesn't allow spaces. You might need to convert it from a local file path. Substitute:
with
Re: QDesktopServices open url & local file & pdf or doc
Dear all,
thank you very much for invaluable inputs.
I found that using is quite useful but on linux systems (, mine is ubuntu 11.04), it can't be used with urls like
Code:
www.qtcenter.org (web addresses)
It does open with So after some search I came across I have tested it on WinXP, Win7, Ubuntu 11.04, MacOSX with success. I have tried opening following Urls with it (successfully):
Quote:
/home (It's a dir path)
/usr/local (It's a dir path)
/home/rupesh/Pictures/1.jpg (it's a file)
/home/rupesh/Pictures/1 2 3 4.jpg (it's a file, please note spaces in file name)
/home/rupesh/Pictures/1.pdf (it's a file)
/home/rupesh/Pictures/1 2 3 4.pdf (it's a file, please note spaces in file name)
http://www.microsoft.com
www.microsoft.com
By the way the code I wrote was
Quote:
return QDesktopServices::openUrl( QUrl::fromUserInput( theUrl ));
Please give me a feedback if you use it and come across any issues.
Thank you
Rupesh
Re: QDesktopServices open url & local file & pdf or doc
Why did you feel the need to resurrect a thread that has been dormant for five years to tell us about a documented function that did not exist until 2009 (Qt 4.6) and could not have been the solution the OP was looking for?
Quote:
Originally Posted by
rupeshbhurke
I found that using
is quite useful but on linux systems (, mine is ubuntu 11.04), it can't be used with urls like
Code:
www.qtcenter.org (web addresses)
Why would you expect it to do anything useful with that? "www.qtcentre.org" is not a local file is it?