Qt/Mac-Specific IssuesThis file outlines known issues and possible workarounds for limitations on Mac OS X with Qt. Contact Trolltech support if you find additional issues which are not covered here. See also the document Qt/Mac is Mac OS X Native.
GUI ApplicationsGUI Applications must be run out of a bundle (something like widgets.app/) or using the open(1) command. Mac OS X needs this to dispatch events correctly, as well as gaining access to the menu bar. If you are using older versions of GDB you must run with the full path to the executable. Later versions allow you to pass the bundle name on the command line. QCursorMac OS X only supports 16x16 custom cursors. For now the only workaround to this problem is to use a small customs cursors (16x16) with QCursor. PaintingMac OS X always double buffers the screen so the Qt::WA_PaintOnScreen attribute has no effect. Also it is impossible to paint outside of a paint event so Qt::WA_PaintOutsidePaintEvent has no effect either. Library SupportBundle-Based LibrariesIf you want to incorporate dynamic libraries as part of your Mac OS X application bundle (the application directory), then you place these into a directory called Frameworks, a subdirectory of the application bundle. The application finds these dynamic libraries if the libraries have an install name of "@executable_path/../Frameworks/libname.dylib. If you use qmake and Makefiles, use the QMAKE_LFLAGS_SONAME setting: QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../Frameworks/ Alternatively you can modify the intall name using the install_name_tool(1) command line tool. See its manpage for more information. Note that the DYLD_LIBRARY_PATH environment variable will override these settings, and any other default paths such as a lookup of dynamic libraries inside /usr/lib and similar default locations. Combining LibrariesIf you want to build a new dynamic library combining the Qt 4.0 dynamic libraries, you need to introduce the ld -r flag. Then relocation information is stored in the the output file, so that this file could be the subject of another ld run. This is done by setting the -r flag in the .pro file, and the LFLAGS settings. Initialization Orderdyld(1) will call global static initializers in the order in which they are linked into your application. If a library links against Qt and references globals in Qt (from global initializers in your own library) you should be sure to link against Qt before your library, otherwise the result will be undefined (as Qt's global initializers have not been called yet). Compiler SettingsCompile-Time FlagsThere are two flags that are helpful when wanting to define Mac OS X specific code:
Q_OS_MAC is defined as a convenience and is available whenever Q_OS_DARWIN is defined. If you desire to define for specific versions of Mac OS X, use the availability macros defined in /usr/include/AvailabilityMacros.h. See QSysInfo for information on runtime version checking. Mac OS X Native API AccessAccessing the Bundle PathThe Mac OS X application is actually a directory (ending with .app). This directory has various sub-directories and sources. In case you want to place for example the plugin directory, inside this bundle, then you need to find out where the bundle resides on the disk. The following code will do this: CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); qDebug("Path = %s", pathPtr); CFRelease(pluginRef); CFRelease(macPath); Do not forget to protect this code with an #if defined(Q_WS_MAC) macro if you are deploying on more than one platform. Translating the Application Menu and Native DialogsThe items in the Application Menu will be merged correctly for your localized application, but they will not show up translated until you add a localized resource folder inside the Bundle. See: http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/index.html And look for the heading: Adding Localized Resources The main thing you need to do is create a file called locversion.plist. Here is an example one for Norwegian: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>LprojCompatibleVersion</key> <string>123</string> <key>LprojLocale</key> <string>no</string> <key>LprojRevisionLevel</key> <string>1</string> <key>LprojVersion</key> <string>123</string> </dict> </plist> Then when you run the application with your preferred language set to Norwegian you should see menu items like "Avslutt" instead of "Quit". User InterfaceRight-Mouse ClicksIf you want to provide right-mouse click support for Mac OS X, use the QContextMenuEvent class. This will map to a context menu event, in other words a menu that will display a popup selection. This is the most common use of right-mouse clicks, and maps to a control-click with the Mac OS X one-button mouse support. Menu BarQt/Mac will automatically detect your menu bars for you and turn them into Mac native menubars. Fitting this into your existing Qt application will normally be automatic, however, if you have special needs the Qt/Mac implementation currently selects a menu bar by starting at the active window (i.e. QApplication::activeWindow()), and applying:
The above 3 guidelines are followed all the way up the parent window chain until one of the above is satisifed. If all else fails a default menu bar will be created, the default menu bar on Qt/Mac is an empty menu bar, however you can create a different default menu bar by creating a parentless QMenuBar; the first one created will be designated the default menu bar, and will be used whenever a default menu bar is needed. Special KeysTo provide the expected behavior for Qt applications on Mac OS X, the Qt::Meta, Qt::MetaModifier, and Qt::META enum values correspond to the Control keys on the standard Macintosh keyboard, and the Qt::Control, Qt::ControlModifier, and Qt::CTRL enum values correspond to the Command keys. LimitationsMenu Actions
Native WidgetsQt/Mac has support for sheets, drawers. Represented by Qt::Sheet and Qt::Drawer in the window flags respectiviely. Brushed metal windows are also possible using Qt::WA_MacMetalStyle window attribute. |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le Qt Developer Network au hasardComment fermer une applicationLe Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.1 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com