PythonQt.QtGui.QDesktopServices · declarations 001
Back to PythonQt.QtGui.QDesktopServices
openUrl
openUrl(url: Any) -> bool
X.openUrl(url) -> bool
Supplemental documentation: Qt 5 reference:
[static] bool QDesktopServices::openUrl(const QUrl \&url)
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.
The following example opens a file on the Windows file system residing on a path that contains spaces:
QDesktopServices::openUrl(QUrl("file:///C:/Program Files", QUrl::TolerantMode));
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.
For example, the following URL contains a recipient (user@foo.com), a subject
(Test), and a message body (Just a test):
mailto:user@foo.com?subject=Test&body=Just a test
Warning: Although many e-mail clients can send attachments and are Unicode-aware, the user may have configured their client without these features. Also, certain e-mail clients (e.g., Lotus Notes) have problems with long URLs.
Warning: A return value of true indicates that the application has successfully
requested the operating system to open the URL in an external application. The external
application may still fail to launch or fail to open the requested URL. This result will
not be reported back to the application.
Warning: URLs passed to this function on iOS will not load unless their schemes are
listed in the LSApplicationQueriesSchemes key of the application's Info.plist file.
For more information, see the Apple Developer Documentation for
canOpenURL(_:).
For example, the following lines enable URLs with the HTTPS scheme:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
</array>
See also setUrlHandler().
Upstream PySide2 reference signatures (binding differences may apply):
openUrl(url: PySide2.QtCore.QUrl) -> bool
Source: https://doc.qt.io/archives/qt-5.15/qdesktopservices.html#openUrl
setUrlHandler
setUrlHandler(scheme: str, receiver: Any, method: str) -> None
X.setUrlHandler(scheme, receiver, method)
Supplemental documentation: Qt 5 reference:
[static] void QDesktopServices::setUrlHandler(const QString \&scheme, QObject *receiver, const char *method)
Sets the handler for the given scheme to be the handler method provided by the receiver object.
This function provides a way to customize the behavior of openUrl(). If openUrl() is called with a URL with the specified scheme then the given method on the receiver object is called instead of QDesktopServices launching an external application.
The provided method must be implemented as a slot that only accepts a single QUrl argument.
class MyHelpHandler : public QObject
{
Q_OBJECT
public:
...
public slots:
void showHelp(const QUrl &url);
};
QDesktopServices::setUrlHandler("help", helpInstance, "showHelp");
To use this function for receiving data from other apps on iOS you also need to add the
custom scheme to the CFBundleURLSchemes list in your Info.plist file:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>
For more information, see the Apple Developer Documentation for Communicating with Other Apps Using Custom URLs.
Warning: It is not possible to claim support for some well known URL schemes, including http and https. This is only allowed for Universal Links.
To claim support for http and https the above entry in the Info.plist file is not allowed. This is only possible when you add your domain to the Entitlements file:
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:your.domain.com</string>
</array>
iOS will search for /.well-known/apple-app-site-association on your domain, when the application is installed. If you want to listen to https://your.domain.com/help?topic\=ABCDEF you need to provide the following content there:
{
"applinks": {
"apps": [],
"details": [{
"appIDs" : [ "ABCDE12345.com.example.app" ],
"components": [{
"/": "/help",
"?": { "topic": "?*"}
}]
}]
}
}
For more information, see the Apple Developer Documentation for https://developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app[Supporting Associated Domains}.
If setUrlHandler() is used to set a new handler for a scheme which already has a handler, the existing handler is simply replaced with the new one. Since QDesktopServices does not take ownership of handlers, no objects are deleted when a handler is replaced.
Note that the handler will always be called from within the same thread that calls QDesktopServices::openUrl().
You must call unsetUrlHandler() before destroying the handler object, so the destruction of the handler object does not overlap with concurrent invocations of openUrl() using it.
See also openUrl() and unsetUrlHandler().
Upstream PySide2 reference signatures (binding differences may apply):
setUrlHandler(scheme: str, receiver: PySide2.QtCore.QObject, method: str) -> None
Source: https://doc.qt.io/archives/qt-5.15/qdesktopservices.html#setUrlHandler
unsetUrlHandler
unsetUrlHandler(scheme: str) -> None
X.unsetUrlHandler(scheme)
Supplemental documentation: Qt 5 reference:
[static] void QDesktopServices::unsetUrlHandler(const QString \&scheme)
Removes a previously set URL handler for the specified scheme.
Call this function before the handler object that was registered for scheme is destroyed, to prevent concurrent openUrl() calls from continuing to call the destroyed handler object.
See also setUrlHandler().
Upstream PySide2 reference signatures (binding differences may apply):
unsetUrlHandler(scheme: str) -> None
Source: https://doc.qt.io/archives/qt-5.15/qdesktopservices.html#unsetUrlHandler