IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt for iOS

Provides insight into Qt's iOS port and how to use it.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Qt for iOS

Qt's iOS port allows you to run Qt applications on iOS devices, such as iPhones, iPads, and iPod Touches.

 

Supported Configurations

The following configurations are supported.

Target Platform

Architecture

Build Environment

Notes

iOS 13, iOS 14, iOS 15, iOS 16

armv8 (arm64)

Xcode 12 (iOS 14 SDK), {Xcode 13} (iOS 15 SDK), Xcode 14 (iOS 16 SDK)

 

Getting Started

Qt supports you in building, testing, and deploying applications for iOS. Qt applications are typically defined using the CMake or qmake build tools. Both tools can generate an .xcodeproj file that can then be loaded and built from the command line, or with Xcode. Qt Creator also directly supports building, running, debugging, and profiling CMake and qmake projects for iOS.

The minimum deployment target for Qt applications is specified in Supported Platforms.

Setting Up the Development Environment

You can download the Qt installers from the Downloads page. For more information, see Getting Started with Qt.

Before installing Qt, you first need to install Xcode. You will find it in the Mac App Store here.

As recommended by Apple, you should always use the latest Xcode version when building your applications for the App Store. In practice this means you also need the latest version of macOS to develop apps with Qt, due to Xcode's system requirements.

For running Qt applications on your Mac or in the simulator that comes with Xcode, this is all you need. However, for running applications on a mobile device and/or publishing your applications in the App Store, you must join the Apple Developer Program, and set up developer certificates and provisioning profiles. The easiest solution is to use a profile that takes any App ID (a *).

Before building any Qt applications, you should test that Xcode is set up correctly, for example, by running one of the standard Xcode application templates on your device.

Building Applications from the Command Line

Use CMake or qmake to define how to build your iOS application. Both CMake and qmake can generate an xcodeproj file, which can then be loaded and built from the command line.

Using CMake

The qt-cmake convenience script located in <Qt-dir>/<version>/ios/bin/ will take care of setting up the toolchain and correct architectures for you.

Using qt-cmake convenience script:

 
Sélectionnez
&lt;Qt-dir&gt;/&lt;version&gt;/ios/bin/qt-cmake &lt;source-dir&gt;

Using the generated xcodeproj file, you can either use Xcode to build your application or run xcodebuild from the command line. For a list of available targets and schemes for your application, run the following command:

 
Sélectionnez
xcodebuild -list -project &lt;your-app&gt;.xcodeproj

Then, run xcodebuild build, passing in your application details:

 
Sélectionnez
xcodebuild build -allowProvisioningUpdates -project &lt;your-app&gt;.xcodeproj -scheme &lt;your-scheme&gt; -configuration Debug -destination "generic/platform=iOS" -destination-timeout 1 ENABLE_ONLY_ACTIVE_RESOURCES=NO
Using qmake

First, define how to build the application using qmake. Then, use the generated xcodeproj file to build the application, either in Xcode or from the command line.

 
Sélectionnez
qmake &lt;your-app&gt;.pro

qmake creates a wrapper Makefile that in turns calls xcodebuild, so you can run make to build your application:

 
Sélectionnez
make -j8

Note that you must re-import the project if its setup changes, for example, when adding or removing source files.

Customizing Xcode project settings

The QMAKE_MAC_XCODE_SETTINGS qmake variable can be used to customize Xcode settings, for example:

 
Sélectionnez
development_team.name = DEVELOPMENT_TEAM
development_team.value = &lt;your-team-id&gt;
QMAKE_MAC_XCODE_SETTINGS += development_team

Other qmake variables are also useful:

 
Sélectionnez
QMAKE_TARGET_BUNDLE_PREFIX = com.&lt;your-company&gt;
QMAKE_BUNDLE = &lt;your-app&gt;

Building Applications with Qt Creator

You can find information on how to set up and run Apple mobile device applications in Qt Creator's manual:

As mentioned previously, you must have Xcode installed.

Using Objective-C Code in Qt Applications

Clang, the compiler used for applications on Apple Platforms, allows mixing C++ and Objective-C code. To enable this mode use the .mm extension for the relevant source files and add them to your project as usual.

With CMake:

 
Sélectionnez
target_sources(myapp PRIVATE objc_code.mm)

With qmake:

 
Sélectionnez
SOURCES += objc_code.mm

You can then use Objective-C frameworks from Apple's Developer Library in your Qt applications.

To expose functionality to the rest of your application, without having to rename all your source files, declare helper functions in a header, and implement the functionality in an Objective-C++ source file:

 
Sélectionnez
// objc_code.h
QString localizedHostName();

// objc_code.mm
#include &lt;Foundation/NSHost.h&gt;
QString localizedHostName()
{
    return QString::fromNSString(NSHost.currentHost.localizedName);
}

Examples for iOS

In Qt Creator, tested examples on iOS can be looked up. Use the ios keyword to search for examples in the Qt Creator Welcome mode. Note that some examples may have limited functionality.

For a list of examples known to work on iOS devices, visit Qt for iOS Examples.

Related Topics

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+