How I can build my app with CODE_SIGN_ENTITLEMENTS?

  • Hi everyone!

    I have a problem with CODE_SIGN_ENTITLEMENTS flag. This flag I need because I trying to use iCloudKit.framework in my application. I've implemented the manager to work with iCloud API but I can't test it. Because when I run my app the app crashed with reason:
    2014-11-10 12:47:08.822 QtForumReader[3888:324405] An uncaught exception was raised
    2014-11-10 12:47:08.823 QtForumReader[3888:324405] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to establish valid container/bundleID information'
    *** First throw call stack:
    0 CoreFoundation 0x00007fff8fdfd64c __exceptionPreprocess + 172
    1 libobjc.A.dylib 0x00007fff89bec6de objc_exception_throw + 43
    2 CloudKit 0x00007fff8ddd1b31 -[CKContainer _synchronouslySendContextInformation] + 1350
    3 CloudKit 0x00007fff8ddd2b55 -[CKContainer connection] + 3080
    4 CloudKit 0x00007fff8ddd2e00 -[CKContainer daemonWithErrorHandler:] + 50
    5 CloudKit 0x00007fff8ddd91c8 -[CKContainer(ApplicationPermission) requestApplicationPermission:completionHandler:] + 121
    6 libQtForum.dylib 0x00000001148a4ce8 -[CloudKitManager requestDiscoverabilityPermission:] + 104
    7 libQtForum.dylib 0x00000001148a0df6 _ZN15QfCloudSettings32requestDiscoverabilityPermissionENSt3__18functionIFvbEEE + 182
    8 libQtForum.dylib 0x00000001148f9eeb _ZN13QForumManager23loadApplicationSettingsEv + 91
    9 libQtForum.dylib 0x00000001148fb6f7 _ZN13QForumManagerC2EP10QQuickItem + 583
    10 libQtForum.dylib 0x00000001148aabd8 _ZN11QQmlPrivate10createIntoI13QForumManagerEEvPv + 24
    11 QtQml 0x000000010ccefef5 _ZNK8QQmlType6createEv + 69
    12 QtQml 0x000000010cd549e1 _ZN17QQmlObjectCreator14createInstanceEiP7QObjectb + 993
    13 QtQml 0x000000010cd58ba5 _ZN17QQmlObjectCreator18setPropertyBindingEP16QQmlPropertyDataPKN3QV412CompiledData7BindingE + 565
    14 QtQml 0x000000010cd56743 _ZN17QQmlObjectCreator13setupBindingsERK9QBitArray + 1811
    15 QtQml 0x000000010cd5a73f _ZN17QQmlObjectCreator16populateInstanceEiP7QObjectS1_P16QQmlPropertyDataRK9QBitArray + 1487
    16 QtQml 0x000000010cd557d7 _ZN17QQmlObjectCreator14createInstanceEiP7QObjectb + 4567
    17 QtQml 0x000000010cd5447b _ZN17QQmlObjectCreator6createEiP7QObjectP26QQmlInstantiationInterrupt + 1435
    18 QtQml 0x000000010cce1e6e _ZN20QQmlComponentPrivate11beginCreateEP15QQmlContextData + 1022
    19 QtQml 0x000000010cce1a21 _ZN13QQmlComponent6createEP11QQmlContext + 97
    20 QtQml 0x000000010cd4d62f _ZN28QQmlApplicationEnginePrivate13_q_finishLoadEP7QObject + 111
    21 QtQml 0x000000010cd4d5a9 _ZN28QQmlApplicationEnginePrivate9startLoadERK4QUrlRK10QByteArrayb + 185
    22 QtQml 0x000000010cd4dbf2 _ZN21QQmlApplicationEngine4loadERK4QUrl + 34
    23 QtForumReader 0x000000010ba3be05 main + 1877
    24 QtForumReader 0x000000010ba3b5c4 start + 52
    libc++abi.dylib: terminating with uncaught exception of type NSException
    The program has unexpectedly finished.

    To solve this I need to build my app with Entitlements.plist file where I need to setup iCloud settings for app. And I've created this file also I've configure my Developer Provision Profile if Apple Developer Admin Panel.

    I've tried use make like:
    /usr/bin/make" -j 4 CODE_SIGN_ENTITLEMENTS=/Volumes/Documents/PROJECTS/MyProjects/GIT_IOS_5/QtForumReader/Desktop/1.x/build-QtForumProject-Desktop_Qt_5_4_clang_64bit-Release/../QtForumProject/QtForumReader/Entitlements.plist CODE_SIGN_IDENTITY='Mac Developer'

    Could you help me with this problem? Thanks for the any help.

  • Hi everyone!

    I've found the solution of my problem with iCloud. I need few days to prepare documentation with this and then I'll post it here.

  • Hi everyone!

    At last I can post the solution how to use iCloud with your Qt project on Mac OS X.

    The first you need to understand the iCloud supports only for Mac OS and if your app will ported to any other OS you need think about using something like DropBox. In my case app will supported only Mac OS.

    In my application I've used iCloudKit API this API has been added in last version of Mac OS 10.10, so you can't use this API in older versions.

    So let's start our small instruction how to add iCloud Kit to your app.

    1. You need to create class with iCloud Kit API. Because iCloud Kit supported Objective-C/C++ you need to create this class using Objective-C/C++. I've prepared my class which you can use in your Qt app.
      1.1. Download class from "url":
      1.2. Unzip to source folder of your project.
      1.3. Add code to file where you need to use iCloud Kit Api:
      #include "CloudKitManager/qfcloudsettings.h"

    1.4. How to use:
    QString appName = qApp->applicationName().replace(" ", "").replace("_", "").replace("-", "");
    QString str = QString("iCloud.%1.%2").arg(qApp->organizationDomain()).arg(appName.toLower());
    QfCloudSettings::defaultManager(str, this);
    QfCloudSettings::defaultManager()->requestDiscoverabilityPermission([this](bool flag) {

             //Some code here


    1. Open your Apple Developer Admin Page and enable to your application iCloudKit service.
    2. Convert your Qt project to Xcode project:
      qmake -spec macx-xcode

    This needs because Xcode must create Entitlements file. This file need to use iCloudKit in your project.

    1. Create a new script phase:
      4.1. Open your_app.xcodeproj in Xcode.
      4.2. Select your application target.
      4.3. Select "Build Phases" tab.
      4.4. Click to "+" button and select "New Run Script Phase".
      4.5. Add code like this:
      /Volumes/Documents/Applications/Qt/Qt5.4.0/5.4/clang_64/bin/macdeployqt $BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME -executable=$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/Contents/MacOS/$PROJECT_NAME -qmldir=$BUILT_PRODUCTS_DIR/../qml

    Where /Volumes/Documents/Applications/Qt/Qt5.4.0/5.4/clang_64 is a path to your version of Qt.

    1. Clean and build your app.

    This must works!

    Some issues which could be with open your project to another Mac:

    1. Project is empty. This happened because qmake create Xcode project with full path to files. To fix this bug you need to open your_app.xcodeprj/project.pbxproj in any Text Editor and replace full paths to new paths. I recommend to remove all path to new paths. But you should be careful with this.

    If you have any questions or problem let me know and I'll help you with them.

    P.S. Now I trying to optimise this steps and removed Xcode from build process. But I still have small issues with codesign of my app bundle. In this case I need to create correct provision and certificate. So I need more time to find solution for QtCreator. I will post new information here.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.