Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Developing Qt Applications on Mac OS X

Mac OS X is a UNIX platform and behaves similar to other Unix-like platforms. The main difference is X11 is not used as the primary windowing system. Instead, Mac OS X uses its own native windowing system that is accessible through the Carbon and Cocoa APIs. Application development on Mac OS X is done using Xcode Tools, an optional install included on every Mac with updates available from Apple's developer website. Xcode Tools includes Apple-modified versions of the GCC compiler.

What Versions of Mac OS X are Supported?

As of Qt 4.5, Qt supports Mac OS X versions 10.3 (for deployment only, not for development), 10.4 and 10.5. It is usually in the best interest of the developer and user to be running the latest updates to any version. We test internally against Mac OS X 10.3.9 and Mac OS X 10.4.11 as well as the updated release of Mac OS X 10.5.

Carbon or Cocoa?

Historically, Qt has used the Carbon toolkit, which supports 32-bit applications on Mac OS X 10.3 and up. Qt 4.5 adds support for the Cocoa toolkit, which requires 10.5 and provides 64-bit support.

This detail is typically not important to Qt application developers. Qt is cross-platform across Carbon and Cocoa, and Qt applications behave the same way when configured for either one. Eventually, the Carbon version will be discontinued. This is something to keep in mind when you consider writing code directly against native APIs.

The current binary for Qt is built for Carbon. If you want to choose which framework Qt will use, you must build from scratch. Carbon or Cocoa is chosen when configuring the package for building. The configure process selects Carbon by default, to specify Cocoa use the -cocoa flag. configure for a 64-bit architecture using one of the -arch flags (see Universal Binaries).

Currently, Apple's GCC 4.0.1 is used by default. When building on 10.5, Apple's GCC 4.2 is also available and selectable with the configure flag: -platform macx-g++42. GCC 3.x will not work. Experimental LLVM-GCC support is available by passing in the -platform macx-llvm flag.

The following table summarizes the different versions of Mac OS X and what capabilities are used by Qt.

Mac OS X VersionCat NameNative API Used by QtBits available to address memoryCPU Architecture SupportedDevelopment Platform
10.3PantherCarbon32PPCNo
10.4TigerCarbon32PPC/IntelYes
10.5LeopardCarbon32PPC/IntelYes
10.5LeopardCocoa32/64PPC/IntelYes

Which One Should I Use?

Carbon and Cocoa both have their advantages and disadvantages. Probably the easiest way to determine is to look at the version of Mac OS X you are targetting. If you are starting a new application and can target 10.5 and up, then please consider Cocoa only. If you have an existing application or need to target earlier versions of the operating system and do not need access to 64-bit or newer Apple technologies, then Carbon is a good fit. If your needs fall in between, you can go with a 64-bit Cocoa and 32-bit Carbon universal application with the appropriate checks in your code to choose the right path based on where you are running the application.

Universal Binaries

In 2006, Apple begin transitioning from PowerPC (PPC) to Intel (x86) systems. Both architectures are supported by Qt. The release of Mac OS X 10.5 in October 2007 added the possibility of writing and deploying 64-bit GUI applications. Qt 4.5 supports both the 32-bit (PPC and x86) and 64-bit (PPC64 and x86-64) versions of PowerPC and Intel-based systems are supported.

Universal binaries are used to bundle binaries for more than one architecture into a single package, simplifying deployment and distribution. When running an application the operating system will select the most appropriate architecture. Universal binaries support the following architectures; they can be added to the build at configure time using the -arch arguments:

ArchitectureFlag
Intel, 32-bit-arch x86
Intel, 64-bit-arch x86_64
PPC, 32-bit-arch ppc
PPC, 64-bit-arch ppc64

If there are no -arch flags specified, configure builds for the 32-bit architecture, if you are currently on one. Universal binaries were initially used to simplify the PPC to Intel migration. You can use -universal to build for both the 32-bit Intel and PPC architectures.

Note: The -arch flags at configure time only affect how Qt is built. Applications are by default built for the 32-bit architecture you are currently on. To build a universal binary, add the architectures to the CONFIG variable in the .pro file:

 CONFIG += x86 ppc x86_64 ppc64

Day-to-Day Application Development on OS X

On the command-line, applications can be built using qmake and make. Optionally, qmake can generate project files for Xcode with -spec macx-xcode. If you are using the binary package, qmake generates Xcode projects by default; use -spec macx-gcc to generate makefiles.

The result of the build process is an application bundle, which is a directory structure that contains the actual application executable. The application can be launched by double-clicking it in Finder, or by referring directly to its executable from the command line, i. e. myApp.app/Contents/MacOS/myApp.

If you wish to have a command-line tool that does not use the GUI (e.g., moc, uic or ls), you can tell qmake not to execute the bundle creating steps by removing it from the CONFIG in your .pro file:

 CONFIG -= app_bundle

Deployment - "Compile once, deploy everywhere"

In general, Qt supports building on one Mac OS X version and deploying on all others, both forward and backwards. You can build on 10.4 Tiger and run the same binary on 10.3 and 10.5.

Some restrictions apply:

  • Some functions and optimization paths that exist in later versions of Mac OS X will not be available if you build on an earlier version of Mac OS X.
  • The CPU architecture should match.
  • Cocoa support is only available for Mac OS X 10.5 and up.

Universal binaries can be used to provide a smorgasbord of configurations catering to all possible architectures.

Mac applications are typically deployed as self-contained application bundles. The application bundle contains the application executable as well as dependencies such as the Qt libraries, plugins, translations and other resources you may need. Third party libraries like Qt are normally not installed system-wide; each application provides its own copy.

The most common way to distribute applications is to provide a compressed disk image (.dmg file) that the user can mount in Finder. The Mac deployment tool (macdeployqt) can be used to create the self-contained bundles, and optionally also create a .dmg archive. See the Mac deployment guide for more information about deployment. It is also possible to use an installer wizard. More information on this option can be found in Apple's documentation.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 56
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 93
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 32
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 231
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

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.5
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 !
 
 
 
 
Partenaires

Hébergement Web