[Solved] Bundle files along with Qt iOS app



  • How can i bundle some files with the Qt iOS app and deploy it on the device. I need to deploy some configuration files and some image files which should be read from the app bundle at Runtime. I can do it by using the Resource file and i cannot do that because i need actual absolute path of the file. Because i am using these image files for the QML files inside my application. (Setting the image to QML will be done after parsing the application XML file which will take only absolute path of the image file). is there any way to bundle external files(images..) with Qt iOS application.



  • Finally i have found the solution for this problem by my own.... :)
    The deployment of files along with the application package in iOS is similar to that of doing in Mac. here is the .pro file,
    @
    TARGET = YourApp
    TEMPLATE = app

    deployment.files = ../YourApp/images
    deployment.path =
    QMAKE_BUNDLE_DATA += deployment
    @

    So the directory "images" with its contents will get automatically copied to the iOS application package (YourApp.app).. If you explore the YourApp.app package you can see the images directory inside it.



  • Hi, I'd testing what you have provided but it isn't working with iOS for me, can you help in this regard please

    as well is there anything spefic for iOS where I can use it in my else statement, something like that I do have in my code

    @unix:!symbian:!maemo5:!win:!android:!macx {
    #Special case for N950 that works, all other devices will use the else case
    DEFINES+=harmattan
    dir1.files = resourc/*
    dir1.path = /opt/$${TARGET}
    INSTALLS += dir1
    } else : android {
    #Special case for android that works, all other devices will use the else case
    dir1.files = resourc/*
    dir1.path = /assets
    INSTALLS += dir1
    } else : macx {
    #Special case for mac that works, all other devices will use the else case
    dir1.files = resourc
    dir1.path = Contents/Resources
    QMAKE_BUNDLE_DATA += dir1
    }
    else {
    dir1.source += resourc/*
    DEPLOYMENTFOLDERS = dir1
    }
    @



  • I don't know what you are exactly trying to do. But if u do like what i have mentioned above, then it should work. I have done that only for iOS. Once the packaging is done, if you open your .app file then you can see the directory which u have specified copied inside it... The path which you are specifying for the directory should be relative path that is what i mentioned "../YourApp/images"



  • Currently, it's not working for me, yes am trying to do as you have suggested

    I'm opening up my project into xCode and doing it there



  • [quote author="Arun P K" date="1382347850"]I don't know what you are exactly trying to do. But if u do like what i have mentioned above, then it should work. I have done that only for iOS. Once the packaging is done, if you open your .app file then you can see the directory which u have specified copied inside it... The path which you are specifying for the directory should be relative path that is what i mentioned "../YourApp/images"[/quote]

    so in a concrete example if i have :

    @TARGET = YourApp
    TEMPLATE = app

    deployment.files = ../YourApp/qml/YouApp/main.qml
    deployment.path =
    QMAKE_BUNDLE_DATA += deployment@

    would i load the qml like:

    @ QmlApplicationViewer viewer;
    ...
    viewer.setMainQmlFile(QLatin1String("qml/YourApp/main.qml"));@

    or like:

    @ viewer.setMainQmlFile(QLatin1String("../YourApp/qml/YourApp/main.qml"));@

    or

    @ viewer.setMainQmlFile(QLatin1String("qrc:/../YourApp/qml/YourApp/main.qml"));@

    ? is there an example out there that works on ios ?



  • Hiya,
    Did anybody get this working?
    Thanks
    James



  • I did find an example of loading a QML file via a resource file

    @#include <QtCore>
    #include <QtGui>
    #include <QtDeclarative>
    #include <QtWidgets>

    int main(int argc, char **argv)
    {
    QApplication application(argc, argv);

    QDeclarativeView view;
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    view.setSource(QUrl("qrc:qtios/main.qml"));
    view.show();
    view.raise();
    
    return application.exec&#40;&#41;;
    

    }@

    but if "main.qml" needs to reference other QML files then I become a bit unstuck :-(



  • Finally i have found the issue.

    check qmlapplicationviewer.pri/qtquick1applicationviewer.pri for the iOS deployment configuration

    @else:ios {
    copyCommand =
    for(deploymentfolder, DEPLOYMENTFOLDERS) {
    source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source)
    source = $$replace(source, \\, /)
    target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target)
    target = $$replace(target, \\, /)
    sourcePathSegments = $$split(source, /)
    targetFullPath = $$target/$$last(sourcePathSegments)
    targetFullPath ~= s,/\.?/,/,
    !isEqual(source,$$targetFullPath) {
    !isEmpty(copyCommand):copyCommand += &&
    copyCommand += mkdir -p "$$target"
    copyCommand += && cp -r "$$source" "$$target"
    }
    }
    !isEmpty(copyCommand) {
    copyCommand = echo Copying application data... && $$copyCommand
    !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";"
    QMAKE_POST_LINK += "$$copyCommand"
    export(QMAKE_POST_LINK)
    }
    } @



  • Sorry,

    do not forget to check qmlapplicationviewer.cpp/qtquick1applicationviewer.cpp

    @#if defined(Q_OS_IOS)
    if (!QDir::isAbsolutePath(path))
    return QString::fromLatin1("%1/%2")
    .arg(QCoreApplication::applicationDirPath(), path);
    #elif@


Log in to reply
 

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