1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?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.11</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 ><a href="../qtdoc/index.html">Qt 5.11</a></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">Qt 5.11.2 Reference Documentation</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">7 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 public variable inherited from <a href="../qtcore/qevent.html#public-variables">QEvent</a></li>
<li class="fn">1 static public member inherited from <a href="../qtcore/qevent.html#static-public-members">QEvent</a></li>
<li class="fn">2 protected variables inherited from <a href="../qtcore/qevent.html#protected-variables">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 <a href="../qtdoc/internationalization.html#macos">macOS</a>.</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 <a href="../qtdoc/internationalization.html#macos">macOS</a> only.</p><a name="macos-example"></a>
<h3 >macOS Example</h3>
<p>In order to trigger the event on <a href="../qtdoc/internationalization.html#macos">macOS</a>, 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> 2018 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>