1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \page mac-differences.html
|
---|
30 | \title Qt for Mac OS X - Specific Issues
|
---|
31 | \brief A description of issues with Qt that are specific to Mac OS X.
|
---|
32 | \ingroup platform-specific
|
---|
33 |
|
---|
34 | This file outlines known issues and possible workarounds when
|
---|
35 | using Qt for Mac OS X. Contact Qt's technical support team if you find
|
---|
36 | additional issues which are not covered here. (See also the
|
---|
37 | document \l{qtmac-as-native.html} {Qt is Mac OS X Native}.)
|
---|
38 |
|
---|
39 | \tableofcontents
|
---|
40 |
|
---|
41 | \section1 GUI Applications
|
---|
42 |
|
---|
43 | Mac OS X handles most applications as "bundles". A bundle is a
|
---|
44 | directory structure that groups related files together (e.g.,
|
---|
45 | widgets.app/). GUI applications in particular must be run from a
|
---|
46 | bundle or by using the open(1), because Mac OS X needs the bundle
|
---|
47 | to dispatch events correctly, as well as for accessing the menu
|
---|
48 | bar.
|
---|
49 |
|
---|
50 | If you are using older versions of GDB you must run with the full
|
---|
51 | path to the executable. Later versions allow you to pass the
|
---|
52 | bundle name on the command line.
|
---|
53 |
|
---|
54 | \section1 Painting
|
---|
55 |
|
---|
56 | Mac OS X always double buffers the screen so the
|
---|
57 | Qt::WA_PaintOnScreen attribute has no effect. Also it is
|
---|
58 | impossible to paint outside of a paint event so
|
---|
59 | Qt::WA_PaintOutsidePaintEvent has no effect either.
|
---|
60 |
|
---|
61 | \section1 Library Support
|
---|
62 |
|
---|
63 | \section2 Qt libraries as frameworks
|
---|
64 |
|
---|
65 | By default, Qt is built as a set of frameworks. Frameworks is the
|
---|
66 | Mac OS X "preferred" way of distributing libraries. There are
|
---|
67 | definite advantages to using them. See
|
---|
68 | \l{http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/index.html}
|
---|
69 | {Apple's Framework Programming Guide} for more information.
|
---|
70 |
|
---|
71 | In general, this shouldn't be an issue because qmake takes care of
|
---|
72 | the specifics for you. The
|
---|
73 | \l{http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/index.html}
|
---|
74 | {Framework Programming Guide} discusses issues to keep in mind
|
---|
75 | when choosing frameworks over the more typical, dynamic libraries.
|
---|
76 | However, one point to remember is: \bold {Frameworks always link
|
---|
77 | with "release" versions of libraries}.
|
---|
78 |
|
---|
79 | If you actually want to use a \e{debug} version of a Qt framework,
|
---|
80 | you must ensure that your application actually loads that debug
|
---|
81 | version. This is often done by using the DYLD_IMAGE_SUFFIX
|
---|
82 | environment variables, but that way often doesn't work so well.
|
---|
83 | Instead, you can temporarily swap your debug and release versions,
|
---|
84 | which is documented in
|
---|
85 | \l{http://developer.apple.com/technotes/tn2004/tn2124.html#SECJUSTONELIB}
|
---|
86 | {Apple's "Debugging Magic" technical note}.
|
---|
87 |
|
---|
88 | If you don't want to use frameworks, simply configure Qt with
|
---|
89 | \c{-no-framework}.
|
---|
90 |
|
---|
91 | \section2 Bundle-Based Libraries
|
---|
92 |
|
---|
93 | If you want to use some dynamic libraries in your Mac OS X
|
---|
94 | application bundle (the application directory), create a
|
---|
95 | subdirectory named "Frameworks" in the application bundle
|
---|
96 | directory and place your dynamic libraries there. The application
|
---|
97 | will find a dynamic library if it has the install name
|
---|
98 | \e{@executable_path/../Frameworks/libname.dylib}.
|
---|
99 |
|
---|
100 | If you use \c qmake and Makefiles, use the \c QMAKE_LFLAGS_SONAME setting:
|
---|
101 |
|
---|
102 | \snippet doc/src/snippets/code/doc_src_mac-differences.qdoc 0
|
---|
103 |
|
---|
104 | Alternatively, you can modify the install name using the
|
---|
105 | install_name_tool(1) on the command line. See its manpage for more
|
---|
106 | information.
|
---|
107 |
|
---|
108 | Note that the \c DYLD_LIBRARY_PATH environment variable will
|
---|
109 | override these settings, and any other default paths, such as a
|
---|
110 | lookup of dynamic libraries inside \c /usr/lib and similar default
|
---|
111 | locations.
|
---|
112 |
|
---|
113 | \section2 Combining Libraries
|
---|
114 |
|
---|
115 | If you want to build a new dynamic library combining the Qt 4
|
---|
116 | dynamic libraries, you need to introduce the \c{ld -r} flag. Then
|
---|
117 | relocation information is stored in the output file, so that
|
---|
118 | this file could be the subject of another \c ld run. This is done
|
---|
119 | by setting the \c -r flag in the \c .pro file, and the \c LFLAGS
|
---|
120 | settings.
|
---|
121 |
|
---|
122 | \section2 Initialization Order
|
---|
123 |
|
---|
124 | dyld(1) calls global static initializers in the order they are
|
---|
125 | linked into your application. If a library links against Qt and
|
---|
126 | references globals in Qt (from global initializers in your own
|
---|
127 | library), be sure to link your application against Qt before
|
---|
128 | linking it against the library. Otherwise the result will be
|
---|
129 | undefined because Qt's global initializers have not been called
|
---|
130 | yet.
|
---|
131 |
|
---|
132 | \section1 Compile-Time Flags
|
---|
133 |
|
---|
134 | The follewing flags are helpful when you want to define Mac OS X specific
|
---|
135 | code:
|
---|
136 |
|
---|
137 | \list
|
---|
138 |
|
---|
139 | \o Q_OS_DARWIN is defined when Qt detects you are on a
|
---|
140 | Darwin-based system (including the Open Source version)
|
---|
141 |
|
---|
142 | \o Q_WS_MAC is defined when the Mac OS X GUI is present.
|
---|
143 |
|
---|
144 | \o QT_MAC_USE_COCOA is defined when Qt is built to use the Cocoa framework.
|
---|
145 | If it is not present, then Qt is using Carbon.
|
---|
146 |
|
---|
147 | \endlist
|
---|
148 |
|
---|
149 | A additional flag, Q_OS_MAC, is defined as a convenience whenever
|
---|
150 | Q_OS_DARWIN is defined.
|
---|
151 |
|
---|
152 | If you want to define code for specific versions of Mac OS X, use
|
---|
153 | the availability macros defined in /usr/include/AvailabilityMacros.h.
|
---|
154 |
|
---|
155 | See QSysInfo for information on runtime version checking.
|
---|
156 |
|
---|
157 | \section1 Mac OS X Native API Access
|
---|
158 |
|
---|
159 | \section2 Accessing the Bundle Path
|
---|
160 |
|
---|
161 | The Mac OS X application is actually a directory (ending with \c
|
---|
162 | .app). This directory contains sub-directories and files. It may
|
---|
163 | be useful to place items (e.g. plugins, online-documentation,
|
---|
164 | etc.) inside this bundle. You might then want to find out where
|
---|
165 | the bundle resides on the disk. The following code returns the
|
---|
166 | path of the application bundle:
|
---|
167 |
|
---|
168 | \snippet doc/src/snippets/code/doc_src_mac-differences.qdoc 1
|
---|
169 |
|
---|
170 | Note: When OS X is set to use Japanese, a bug causes this sequence
|
---|
171 | to fail and return an empty string. Therefore, always test the
|
---|
172 | returned string.
|
---|
173 |
|
---|
174 | For more information about using the CFBundle API, see
|
---|
175 | \l{http://developer.apple.com/documentation/CoreFoundation/Reference/CFBundleRef/index.html}
|
---|
176 | {Apple's Developer Website}.
|
---|
177 |
|
---|
178 | Note: QCoreApplication::applicationDirPath() can be used to determine
|
---|
179 | the path of the binary within the bundle.
|
---|
180 |
|
---|
181 | \section2 Translating the Application Menu and Native Dialogs
|
---|
182 |
|
---|
183 | The items in the Application Menu will be merged correctly for
|
---|
184 | your localized application, but they will not show up translated
|
---|
185 | until you
|
---|
186 | \l{http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/Concepts/BundleAnatomy.html#//apple_ref/doc/uid/20001119-105003-BAJFDAAG}
|
---|
187 | {add a localized resource folder} to the application bundle.
|
---|
188 | The main thing you need to do is create a file called
|
---|
189 | locversion.plist. Here is an example for Norwegian:
|
---|
190 |
|
---|
191 | \snippet doc/src/snippets/code/doc_src_mac-differences.qdoc 2
|
---|
192 |
|
---|
193 | Now when you run the application with your preferred language set
|
---|
194 | to Norwegian, you should see menu items like "Avslutt" instead of
|
---|
195 | "Quit".
|
---|
196 |
|
---|
197 | \section1 User Interface
|
---|
198 |
|
---|
199 | \section2 Right-Mouse Clicks
|
---|
200 |
|
---|
201 | If you want to provide right-mouse click support for Mac OS X, use
|
---|
202 | the QContextMenuEvent class. This will map to a context menu
|
---|
203 | event, i.e., a menu that will display a pop-up selection. This is
|
---|
204 | the most common use of right-mouse clicks, and maps to a
|
---|
205 | control-click with the Mac OS X one-button mouse support.
|
---|
206 |
|
---|
207 | \section2 Menu Bar
|
---|
208 |
|
---|
209 | Qt will automatically detect your menu bars for you and turn
|
---|
210 | them into Mac native menu bars. Fitting this into your existing Qt
|
---|
211 | application will normally be automatic. However, if you have
|
---|
212 | special needs, the Qt implementation currently selects a menu
|
---|
213 | bar by starting at the active window
|
---|
214 | (i.e. QApplication::activeWindow()) and applying the following
|
---|
215 | tests:
|
---|
216 |
|
---|
217 | \list 1
|
---|
218 |
|
---|
219 | \i If the window has a QMenuBar, then it is used.
|
---|
220 |
|
---|
221 | \i If the window is modal, then its menu bar is used. If no menu
|
---|
222 | bar is specified, then a default menu bar is used (as
|
---|
223 | documented below).
|
---|
224 |
|
---|
225 | \i If the window has no parent, then the default menu bar is used
|
---|
226 | (as documented below).
|
---|
227 |
|
---|
228 | \endlist
|
---|
229 |
|
---|
230 | These tests are followed all the way up the parent window chain
|
---|
231 | until one of the above rules is satisifed. If all else fails, a
|
---|
232 | default menu bar will be created. Note the default menu bar on
|
---|
233 | Qt is an empty menu bar. However, you can create a different
|
---|
234 | default menu bar by creating a parentless QMenuBar. The first one
|
---|
235 | created will be designated the default menu bar and will be used
|
---|
236 | whenever a default menu bar is needed.
|
---|
237 |
|
---|
238 | Note that using native menu bars introduces certain limitations on
|
---|
239 | Qt classes. See the \l{#Limitations}{list of limitations} below
|
---|
240 | for more information about these.
|
---|
241 |
|
---|
242 | \section2 Special Keys
|
---|
243 |
|
---|
244 | To provide the expected behavior for Qt applications on Mac OS X,
|
---|
245 | the Qt::Meta, Qt::MetaModifier, and Qt::META enum values
|
---|
246 | correspond to the Control keys on the standard Macintosh keyboard,
|
---|
247 | and the Qt::Control, Qt::ControlModifier, and Qt::CTRL enum values
|
---|
248 | correspond to the Command keys.
|
---|
249 |
|
---|
250 | \section1 Limitations
|
---|
251 |
|
---|
252 | \section2 Menu Actions
|
---|
253 |
|
---|
254 | \list
|
---|
255 |
|
---|
256 | \o Actions in a QMenu with accelerators that have more than one
|
---|
257 | keystroke (QKeySequence) will not display correctly, when the
|
---|
258 | QMenu is translated into a Mac native menu bar. The first key
|
---|
259 | will be displayed. However, the shortcut will still be
|
---|
260 | activated as on all other platforms.
|
---|
261 |
|
---|
262 | \o QMenu objects used in the native menu bar are not able to
|
---|
263 | handle Qt events via the normal event handlers.
|
---|
264 | For Carbon, you will have to install a Carbon event handler on
|
---|
265 | the menu bar in order to receive Carbon events that are similar
|
---|
266 | to \l{QMenu::}{showEvent()}, \l{QMenu::}{hideEvent()}, and
|
---|
267 | \l{QMenu::}{mouseMoveEvent()}. For Cocoa, you will have to
|
---|
268 | install a delegate on the menu itself to be notified of these
|
---|
269 | changes. Alternatively, consider using the QMenu::aboutToShow()
|
---|
270 | and QMenu::aboutToHide() signals to keep track of menu visibility;
|
---|
271 | these provide a solution that should work on all platforms
|
---|
272 | supported by Qt.
|
---|
273 |
|
---|
274 | \endlist
|
---|
275 |
|
---|
276 | \section2 Native Widgets
|
---|
277 |
|
---|
278 | Qt has support for sheets and drawers, represented in the
|
---|
279 | window flags by Qt::Sheet and Qt::Drawer respectiviely. Brushed
|
---|
280 | metal windows can also be created by using the
|
---|
281 | Qt::WA_MacMetalStyle window attribute.
|
---|
282 |
|
---|
283 | */
|
---|
284 |
|
---|
285 | /*!
|
---|
286 | \page qt-mac-cocoa-licensing.html
|
---|
287 |
|
---|
288 | \title Contributions to the Following QtGui Files: qapplication_cocoa_p.h, qapplication_mac.mm, qdesktopwidget_mac.mm qeventdispatcher_mac.mm qeventdispatcher_mac_p.h qmacincludes_mac.h qt_cocoa_helpers.mm qt_cocoa_helpers_p.h qwidget_mac.mm qsystemtrayicon_mac.mm
|
---|
289 |
|
---|
290 | \contentspage {Other Licenses Used in Qt}{Contents}
|
---|
291 |
|
---|
292 | \ingroup licensing
|
---|
293 | \brief License information for contributions by Apple, Inc. to specific parts of the Qt for Mac OS X Cocoa port.
|
---|
294 |
|
---|
295 | \legalese
|
---|
296 |
|
---|
297 | Copyright (C) 2007-2008, Apple, Inc.
|
---|
298 |
|
---|
299 | All rights reserved.
|
---|
300 |
|
---|
301 | Redistribution and use in source and binary forms, with or without
|
---|
302 | modification, are permitted provided that the following conditions are met:
|
---|
303 |
|
---|
304 | \list
|
---|
305 | \o Redistributions of source code must retain the above copyright notice,
|
---|
306 | this list of conditions and the following disclaimer.
|
---|
307 | \o Redistributions in binary form must reproduce the above copyright notice,
|
---|
308 | this list of conditions and the following disclaimer in the documentation
|
---|
309 | and/or other materials provided with the distribution.
|
---|
310 | \o Neither the name of Apple, Inc. nor the names of its contributors
|
---|
311 | may be used to endorse or promote products derived from this software
|
---|
312 | without specific prior written permission.
|
---|
313 | \endlist
|
---|
314 |
|
---|
315 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
316 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
317 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
318 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
319 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
320 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
321 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
322 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
323 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
324 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
325 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
326 |
|
---|
327 | \endlegalese
|
---|
328 | */
|
---|