<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qevent.cpp --> <title>QFileOpenEvent 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 >QFileOpenEvent</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="#public-functions">Public Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> <li class="level2"><a href="#macos-example">macOS Example</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QFileOpenEvent Class</h1> <!-- $$$QFileOpenEvent-brief --> <p>The <a href="qfileopenevent.html">QFileOpenEvent</a> class provides an event that will be sent when there is a request to open a file or a URL. <a href="#details">More...</a></p> <!-- @@@QFileOpenEvent --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QFileOpenEvent></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"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qevent.html">QEvent</a></td></tr></table></div><ul> <li><a href="qfileopenevent-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qfileopenevent.html#file">file</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qfileopenevent.html#openFile">openFile</a></b>(QFile &<i>file</i>, QIODevice::OpenMode <i>flags</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QUrl </td><td class="memItemRight bottomAlign"><b><a href="qfileopenevent.html#url">url</a></b>() const</td></tr> </table></div> <ul> <li class="fn">6 public functions inherited from <a href="../qtcore/qevent.html#public-functions">QEvent</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li class="fn">1 property inherited from <a href="../qtcore/qevent.html#properties">QEvent</a></li> <li class="fn">1 static public member inherited from <a href="../qtcore/qevent.html#static-public-members">QEvent</a></li> </ul> <a name="details"></a> <!-- $$$QFileOpenEvent-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qfileopenevent.html">QFileOpenEvent</a> class provides an event that will be sent when there is a request to open a file or a URL.</p> <p>File open events will be sent to the QApplication::instance() when the operating system requests that a file or URL should be opened. This is a high-level event that can be caused by different user actions depending on the user's desktop environment; for example, double clicking on an file icon in the Finder on macOS.</p> <p>This event is only used to notify the application of a request. It may be safely ignored.</p> <p><b>Note: </b>This class is currently supported for macOS only.</p><a name="macos-example"></a> <h3 id="macos-example">macOS Example</h3> <p>In order to trigger the event on macOS, the application must be configured to let the OS know what kind of file(s) it should react on.</p> <p>For example, the following <code>Info.plist</code> file declares that the application can act as a viewer for files with a PNG extension:</p> <pre class="cpp"> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>png</string> </array> <key>CFBundleTypeRole</key> <string>Viewer</string> </dict> </array> </dict> </plist> </pre> <p>The following implementation of a <a href="../qtwidgets/qapplication.html">QApplication</a> subclass prints the path to the file that was, for example, dropped on the Dock icon of the application.</p> <pre class="cpp"> <span class="preprocessor">#include <QApplication></span> <span class="preprocessor">#include <QFileOpenEvent></span> <span class="preprocessor">#include <QtDebug></span> <span class="keyword">class</span> MyApplication : <span class="keyword">public</span> <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span> { <span class="keyword">public</span>: MyApplication(<span class="type">int</span> <span class="operator">&</span>argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv) : <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span>(argc<span class="operator">,</span> argv) { } bool event(<span class="type"><a href="../qtcore/qevent.html#QEvent">QEvent</a></span> <span class="operator">*</span>event) override { <span class="keyword">if</span> (event<span class="operator">-</span><span class="operator">></span>type() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qevent.html#QEvent">QEvent</a></span><span class="operator">::</span>FileOpen) { <span class="type">QFileOpenEvent</span> <span class="operator">*</span>openEvent <span class="operator">=</span> <span class="keyword">static_cast</span><span class="operator"><</span><span class="type">QFileOpenEvent</span> <span class="operator">*</span><span class="operator">></span>(event); <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"Open file"</span> <span class="operator"><</span><span class="operator"><</span> openEvent<span class="operator">-</span><span class="operator">></span>file(); } <span class="keyword">return</span> <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span><span class="operator">::</span>event(event); } }; </pre> </div> <!-- @@@QFileOpenEvent --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$file[overload1]$$$file --> <h3 class="fn" id="file"><a name="file"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QFileOpenEvent::<span class="name">file</span>() const</h3> <p>Returns the file that is being opened.</p> <!-- @@@file --> <!-- $$$openFile[overload1]$$$openFileQFile&QIODevice::OpenMode --> <h3 class="fn" id="openFile"><a name="openFile"></a><span class="type">bool</span> QFileOpenEvent::<span class="name">openFile</span>(<span class="type"><a href="../qtcore/qfile.html">QFile</a></span> &<i>file</i>, <span class="type"><a href="../qtcore/qiodevice.html#OpenModeFlag-enum">QIODevice::OpenMode</a></span> <i>flags</i>) const</h3> <p>Opens a <a href="../qtcore/qfile.html">QFile</a> on the <i>file</i> referenced by this event in the mode specified by <i>flags</i>. Returns <code>true</code> if successful; otherwise returns <code>false</code>.</p> <p>This is necessary as some files cannot be opened by name, but require specific information stored in this event.</p> <p>This function was introduced in Qt 4.8.</p> <!-- @@@openFile --> <!-- $$$url[overload1]$$$url --> <h3 class="fn" id="url"><a name="url"></a><span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> QFileOpenEvent::<span class="name">url</span>() const</h3> <p>Returns the url that is being opened.</p> <p>This function was introduced in Qt 4.6.</p> <!-- @@@url --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</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>