Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 1382

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qdesktopservices.cpp -->
  <title>QDesktopServices Class | Qt GUI 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QDesktopServices</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#url-handlers">URL Handlers</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QDesktopServices Class</h1>
<!-- $$$QDesktopServices-brief -->
<p>The <a href="qdesktopservices.html">QDesktopServices</a> class provides methods for accessing common desktop services. <a href="#details">More...</a></p>
<!-- @@@QDesktopServices -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QDesktopServices&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 4.2</td></tr></table></div><ul>
<li><a href="qdesktopservices-members.html">List of all members, including inherited members</a></li>
<li><a href="qdesktopservices-obsolete.html">Obsolete members</a></li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qdesktopservices.html#openUrl">openUrl</a></b>(const QUrl &amp;<i>url</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdesktopservices.html#setUrlHandler">setUrlHandler</a></b>(const QString &amp;<i>scheme</i>, QObject *<i>receiver</i>, const char *<i>method</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdesktopservices.html#unsetUrlHandler">unsetUrlHandler</a></b>(const QString &amp;<i>scheme</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QDesktopServices-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qdesktopservices.html">QDesktopServices</a> class provides methods for accessing common desktop services.</p>
<p>Many desktop environments provide services that can be used by applications to perform common tasks, such as opening a web page, in a way that is both consistent and takes into account the user's application preferences.</p>
<p>This class contains functions that provide simple interfaces to these services that indicate whether they succeeded or failed.</p>
<p>The <a href="qdesktopservices.html#openUrl">openUrl</a>() function is used to open files located at arbitrary URLs in external applications. For URLs that correspond to resources on the local filing system (where the URL scheme is &quot;file&quot;), a suitable application will be used to open the file; otherwise, a web browser will be used to fetch and display the file.</p>
<p>The user's desktop settings control whether certain executable file types are opened for browsing, or if they are executed instead. Some desktop environments are configured to prevent users from executing files obtained from non-local URLs, or to ask the user's permission before doing so.</p>
<a name="url-handlers"></a>
<h3 id="url-handlers">URL Handlers</h3>
<p>The behavior of the <a href="qdesktopservices.html#openUrl">openUrl</a>() function can be customized for individual URL schemes to allow applications to override the default handling behavior for certain types of URLs.</p>
<p>The dispatch mechanism allows only one custom handler to be used for each URL scheme; this is set using the <a href="qdesktopservices.html#setUrlHandler">setUrlHandler</a>() function. Each handler is implemented as a slot which accepts only a single <a href="../qtcore/qurl.html">QUrl</a> argument.</p>
<p>The existing handlers for each scheme can be removed with the <a href="qdesktopservices.html#unsetUrlHandler">unsetUrlHandler</a>() function. This returns the handling behavior for the given scheme to the default behavior.</p>
<p>This system makes it easy to implement a help system, for example. Help could be provided in labels and text browsers using <b>help://myapplication/mytopic</b> URLs, and by registering a handler it becomes possible to display the help text inside the application:</p>
<pre class="cpp">

  <span class="keyword">class</span> MyHelpHandler : <span class="keyword">public</span> <span class="type"><a href="../qtcore/qobject.html">QObject</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> showHelp(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> <span class="operator">&amp;</span>url);
  };

  <span class="type"><a href="qdesktopservices.html">QDesktopServices</a></span><span class="operator">::</span>setUrlHandler(<span class="string">&quot;help&quot;</span><span class="operator">,</span> helpInstance<span class="operator">,</span> <span class="string">&quot;showHelp&quot;</span>);

</pre>
<p>If inside the handler you decide that you can't open the requested URL, you can just call <a href="qdesktopservices.html#openUrl">QDesktopServices::openUrl</a>() again with the same argument, and it will try to open the URL using the appropriate mechanism for the user's desktop environment.</p>
<p>Combined with platform specific settings, the schemes registered by the <a href="qdesktopservices.html#openUrl">openUrl</a>() function can also be exposed to other applications, opening up for application deep linking or a very basic URL-based IPC mechanism.</p>
<p><b>Note: </b>Since Qt 5, storageLocation() and displayName() are replaced by functionality provided by the <a href="../qtcore/qstandardpaths.html">QStandardPaths</a> class.</p></div>
<p><b>See also </b><a href="../qtwidgets/qsystemtrayicon.html">QSystemTrayIcon</a>, <a href="../qtcore/qprocess.html">QProcess</a>, and <a href="../qtcore/qstandardpaths.html">QStandardPaths</a>.</p>
<!-- @@@QDesktopServices -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$openUrl[overload1]$$$openUrlconstQUrl& -->
<h3 class="fn" id="openUrl"><a name="openUrl"></a><code>[static] </code><span class="type">bool</span> QDesktopServices::<span class="name">openUrl</span>(const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> &amp;<i>url</i>)</h3>
<p>Opens the given <i>url</i> in the appropriate Web browser for the user's desktop environment, and returns <code>true</code> if successful; otherwise returns <code>false</code>.</p>
<p>If the URL is a reference to a local file (i.e&#x2e;, the URL scheme is &quot;file&quot;) then it will be opened with a suitable application instead of a Web browser.</p>
<p>The following example opens a file on the Windows file system residing on a path that contains spaces:</p>
<pre class="cpp">

  <span class="type"><a href="qdesktopservices.html">QDesktopServices</a></span><span class="operator">::</span>openUrl(<span class="type"><a href="../qtcore/qurl.html">QUrl</a></span>(<span class="string">&quot;file:///C:/Documents and Settings/All Users/Desktop&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span><span class="operator">::</span>TolerantMode));

</pre>
<p>If a <code>mailto</code> 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 <code>mailto</code> links are handled by a Web browser.</p>
<p>For example, the following URL contains a recipient (<code>user@foo.com</code>), a subject (<code>Test</code>), and a message body (<code>Just a test</code>):</p>
<pre class="cpp">

  mailto:user@foo<span class="operator">.</span>com<span class="operator">?</span>subject<span class="operator">=</span>Test<span class="operator">&amp;</span>body<span class="operator">=</span>Just a test

</pre>
<p><b>Warning:</b> 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&#x2e;, Lotus Notes) have problems with long URLs.</p>
<p><b>Warning:</b> A return value of <code>true</code> 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.</p>
<p><b>Warning:</b> URLs passed to this function on iOS will not load unless their schemes are listed in the <code>LSApplicationQueriesSchemes</code> key of the application's Info.plist file. For more information, see the Apple Developer Documentation for <a href="https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl">canOpenURL(_:)</a>. For example, the following lines enable URLs with the HTTPS scheme:</p>
<pre class="cpp">

  <span class="operator">&lt;</span>key<span class="operator">&gt;</span>LSApplicationQueriesSchemes<span class="operator">&lt;</span><span class="operator">/</span>key<span class="operator">&gt;</span>
  <span class="operator">&lt;</span>array<span class="operator">&gt;</span>
      <span class="operator">&lt;</span>string<span class="operator">&gt;</span>https<span class="operator">&lt;</span><span class="operator">/</span>string<span class="operator">&gt;</span>
  <span class="operator">&lt;</span><span class="operator">/</span>array<span class="operator">&gt;</span>

</pre>
<p><b>See also </b><a href="qdesktopservices.html#setUrlHandler">setUrlHandler</a>().</p>
<!-- @@@openUrl -->
<!-- $$$setUrlHandler[overload1]$$$setUrlHandlerconstQString&QObject*constchar* -->
<h3 class="fn" id="setUrlHandler"><a name="setUrlHandler"></a><code>[static] </code><span class="type">void</span> QDesktopServices::<span class="name">setUrlHandler</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>scheme</i>, <span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>receiver</i>, const <span class="type">char</span> *<i>method</i>)</h3>
<p>Sets the handler for the given <i>scheme</i> to be the handler <i>method</i> provided by the <i>receiver</i> object.</p>
<p>This function provides a way to customize the behavior of <a href="qdesktopservices.html#openUrl">openUrl</a>(). If <a href="qdesktopservices.html#openUrl">openUrl</a>() is called with a URL with the specified <i>scheme</i> then the given <i>method</i> on the <i>receiver</i> object is called instead of <a href="qdesktopservices.html">QDesktopServices</a> launching an external application.</p>
<p>The provided method must be implemented as a slot that only accepts a single <a href="../qtcore/qurl.html">QUrl</a> argument.</p>
<pre class="cpp">

  <span class="keyword">class</span> MyHelpHandler : <span class="keyword">public</span> <span class="type"><a href="../qtcore/qobject.html">QObject</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> showHelp(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> <span class="operator">&amp;</span>url);
  };

  <span class="type"><a href="qdesktopservices.html">QDesktopServices</a></span><span class="operator">::</span>setUrlHandler(<span class="string">&quot;help&quot;</span><span class="operator">,</span> helpInstance<span class="operator">,</span> <span class="string">&quot;showHelp&quot;</span>);

</pre>
<p>To use this function for receiving data from other apps on iOS you also need to add the custom scheme to the <code>CFBundleURLSchemes</code> list in your Info.plist file:</p>
<pre class="cpp">

  <span class="operator">&lt;</span>key<span class="operator">&gt;</span>CFBundleURLTypes<span class="operator">&lt;</span><span class="operator">/</span>key<span class="operator">&gt;</span>
  <span class="operator">&lt;</span>array<span class="operator">&gt;</span>
      <span class="operator">&lt;</span>dict<span class="operator">&gt;</span>
          <span class="operator">&lt;</span>key<span class="operator">&gt;</span>CFBundleURLSchemes<span class="operator">&lt;</span><span class="operator">/</span>key<span class="operator">&gt;</span>
          <span class="operator">&lt;</span>array<span class="operator">&gt;</span>
              <span class="operator">&lt;</span>string<span class="operator">&gt;</span>myapp<span class="operator">&lt;</span><span class="operator">/</span>string<span class="operator">&gt;</span>
          <span class="operator">&lt;</span><span class="operator">/</span>array<span class="operator">&gt;</span>
      <span class="operator">&lt;</span><span class="operator">/</span>dict<span class="operator">&gt;</span>
  <span class="operator">&lt;</span><span class="operator">/</span>array<span class="operator">&gt;</span>

</pre>
<p>For more information, see the Apple Developer Documentation for <a href="https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/communicating_with_other_apps_using_custom_urls?language=objc">Communicating with Other Apps Using Custom URLs</a>.</p>
<p>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 <a href="qdesktopservices.html">QDesktopServices</a> does not take ownership of handlers, no objects are deleted when a handler is replaced.</p>
<p>Note that the handler will always be called from within the same thread that calls <a href="qdesktopservices.html#openUrl">QDesktopServices::openUrl</a>().</p>
<p><b>See also </b><a href="qdesktopservices.html#openUrl">openUrl</a>() and <a href="qdesktopservices.html#unsetUrlHandler">unsetUrlHandler</a>().</p>
<!-- @@@setUrlHandler -->
<!-- $$$unsetUrlHandler[overload1]$$$unsetUrlHandlerconstQString& -->
<h3 class="fn" id="unsetUrlHandler"><a name="unsetUrlHandler"></a><code>[static] </code><span class="type">void</span> QDesktopServices::<span class="name">unsetUrlHandler</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>scheme</i>)</h3>
<p>Removes a previously set URL handler for the specified <i>scheme</i>.</p>
<p><b>See also </b><a href="qdesktopservices.html#setUrlHandler">setUrlHandler</a>().</p>
<!-- @@@unsetUrlHandler -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>